/使用preg\u replace\u回调代替PHP
我有一个字符串,我需要帮助转换为preg_replace_回调。任何解释方面的帮助都会有所帮助 谢谢/使用preg\u replace\u回调代替PHP,php,Php,我有一个字符串,我需要帮助转换为preg_replace_回调。任何解释方面的帮助都会有所帮助 谢谢 preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1]))); preg_replace('/(?以下是手册中的一个小改动的确切示例: $string = preg_replace_callback( '/(?<=^|[\x09\x20\x2D])
preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1])));
preg_replace('/(?以下是手册中的一个小改动的确切示例:
$string = preg_replace_callback(
'/(?<=^|[\x09\x20\x2D])./',
create_function(
// single quotes are essential here,
// or alternative escape all $ as \$
'$matches',
'return strtoupper($matches[0]);'
),
$string
);
$string=preg\u replace\u回调(
'/(?文档的哪一部分有问题?文档中有点混乱,因为没有前后示例。为什么需要前后示例?您不知道当前代码的功能吗?不知道。我正在修改之前测试websocket服务器。将/e
修改器替换为create_函数
的效果相当相反,因为两者基本上都在下面使用eval
,并且会带来所有问题。使用真正的匿名函数,除非出于某种原因需要同时支持PHP<5.3和某个未来版本的PHP,该版本没有/e
修饰符。
function myfunc($matches)
{
return strtoupper($matches[0]);
}
$string = preg_replace_callback("/(?<=^|[\x09\x20\x2D])./", "myfunc", $string);