Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to uppercase first letter after a hyphen, ie Adam Smith-Jones

Tags:

php

I'm looking for a way to uppercase the first letter/s of a string, including where the names are joined by a hyphen, such as adam smith-jones needs to be Adam Smith-Jones.

ucwords() (or ucfirst() if I split them into firstname, lastname) only does Adam Smith-jones

like image 428
MonOve Avatar asked Jan 23 '12 19:01

MonOve


1 Answers

$string = implode('-', array_map('ucfirst', explode('-', $string)));
like image 121
Milan Kragujević Avatar answered Sep 18 '22 08:09

Milan Kragujević