/ e modifier不建议使用preg_replace_callback而不是PHP

时间:2013-08-29 23:05:26

标签: php

我有一个字符串,我需要帮助转换为preg_replace_callback。任何有关解释的帮助都会有所帮助。

由于

preg_replace('/(?<=^|[\x09\x20\x2D])./e', 'strtoupper("\0")', strtolower(trim($match[1])));

1 个答案:

答案 0 :(得分:0)

以下是手册中的一个小变化的确切示例:

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

或:

function myfunc($matches)
{
  return strtoupper($matches[0]);
}
$string = preg_replace_callback("/(?<=^|[\x09\x20\x2D])./", "myfunc", $string);
相关问题