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

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

Best Answer

$string = implode('-', array_map('ucfirst', explode('-', $string)));
Related Topic