【发布时间】:2014-07-25 14:30:36
【问题描述】:
我现在需要更新一个匿名函数以与 PHP 5.2 兼容。该函数(如下)接受文本并将每个句子的第一个字母大写。
function clean_text($input) {
$output = $input;
$output = preg_replace_callback('/([.!?])\s*(\w)/', function ($matches) {
return strtoupper($matches[1] . ' ' . $matches[2]);
}, ucfirst(strtolower($input)));
return $output;
}
我尝试将函数拉出,但我收到一条错误消息,指出回调中的参数 2 现在丢失。有关如何解决此问题的任何想法?
function clean_text($input) {
function upper_case($input) {
return strtoupper($input[1] . ' ' . $input[2]);
}
$output = preg_replace_callback('/([.!?])\s*(\w)/', upper_case($input), ucfirst(strtolower($input)));
return $output;
}
错误提示:警告:preg_replace_callback() [function.preg-replace-callback]:需要参数 2“U S”作为 有效回调
【问题讨论】:
-
当您尝试退出此功能时遇到的exact 错误是什么?
-
警告:preg_replace_callback() [function.preg-replace-callback]:需要参数 2,'US',才能成为有效的回调
-
你检查过preg_replace_callback()手册页上的示例#2吗?