Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
/使用preg\u replace\u回调代替PHP_Php - Fatal编程技术网

/使用preg\u replace\u回调代替PHP

/使用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_回调。任何解释方面的帮助都会有所帮助

谢谢

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);