1
我有PHP 5.5中的问题:当我使用此代码:警告:preg_replace_callback():修改/ E不能与更换回调使用
$source = preg_replace('/&#(\d+);/me', "utf8_encode(chr(\\1))", $source);
$source = preg_replace('/&#x([a-f0-9]+);/mei', "utf8_encode(chr(0x\\1))", $source);
返回错误
推荐使用:的preg_replace ():该/ e修饰符已过时,使用preg_replace_callback代替
我与preg_replace_callback使用:
$source = preg_replace_callback('/&#(\d+);/me', function($m) { return utf8_encode(chr($m[1])); },$source);
$source = preg_replace_callback('/&#x([a-f0-9]+);/mei', function($m) { return utf8_encode(chr("0x".$m[1])); },$source);
它返回警告:
警告:preg_replace_callback():修改/ E不能与更换回调使用
什么将是实现这一目标的正确的代码?
的问题是与''e'(修改)'你用'preg_replace_callback一起使用'regex'模式中()'function.Remove来自你的正则表达式的'e'(修饰符)'。所以简单的代码看起来像'preg_replace_callback('/&#(\ d +);/m',function($ m){return utf8_encode(chr($ m [1]));},$ source);' –
感谢您的支持,它的工作。 –