-2

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

谢谢

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

1 回答 1

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);
于 2013-08-29T23:16:40.933 回答