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.
Here is a simple function that can convert all the words in a string to title case:
function toTitleCase($string) { return preg_replace_callback('/\w+/', function ($match) { return ucfirst(strtolower($match[0])); }, $string); }