【发布时间】:2016-03-12 07:03:03
【问题描述】:
我有一个函数可以使每个新句子的字符都大写,但是它不能正常工作。仅当新单词与标点符号正对时才有效,而标点符号后有空格则无效。我该如何解决这个问题?
//****************************************************************
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;
结果
我不想?我为什么要这样做?
需要结果
我不想?我为什么要这样做?
【问题讨论】:
-
@rizier123 /e 修饰符已弃用,请改用 preg_replace_callback
标签: php preg-replace uppercase