I have a function that make the character of every new sentence upper case, however, it's not working properly. It only works if the new word is right up against the punctuation mark, and not if there is a space after the punctuation mark. How would I fix this?
//****************************************************************
function ucAll($str) {
return preg_replace_callback('/(?<=^|[\.\?!])[^\.]/', function ($match) {
return strtoupper($match[0]);
}, $str);
} //end of function ucAll($str)
//****************************************************************
$string = "i dont' want to? why should i?";
$string = ucAll($string);
echo $string;
Result
I dont' want to? why should i?
Need Result
I dont' want to? Why should i?