So I have some sentences I am inserting into a database with some auto-correction processes. The following sentence:
$sentence = \"Is this dog your\'s because it
You should of course use ucwords(), but this is how you would do it with a regular expression:
echo preg_replace_callback('/(?<=\s|^)[a-z]/', function($match) {
return strtoupper($match[0]);
}, $sentence);
It makes sure that each lower case character is preceded by a space (or start of the sentence) by using a lookbehind assertion, before it's changed to upper case.