我有一個函數可以讓所有句子的第一個字符大寫,但是由於某種原因,它並沒有對第一個句子的第一個字符進行操作。爲什麼會發生這種情況,我該如何解決?製作所有句子大寫字母的第一個字符
<?php
function ucAll($str) {
$str = preg_replace_callback('/([.!?])\s*(\w)/',
create_function('$matches', 'return strtoupper($matches[0]);'), $str);
return $str;
} //end of function ucAll($str)
$str = ucAll("first.second.third");
echo $str;
?>
結果:
first.Second.Third
預期結果:
First.Second.Third