Php 警告:preg_replace_callback():修饰符/e不能与替换回调一起使用
我对php 5.5有一个问题:当我使用此代码时:Php 警告:preg_replace_callback():修饰符/e不能与替换回调一起使用,php,Php,我对php 5.5有一个问题:当我使用此代码时: $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\u replace():不推荐使用/e修饰符,请改用preg\u replace\u
$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\u replace():不推荐使用/e修饰符,请改用preg\u replace\u回调
我与preg_replace_回调一起使用:
$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不能与替换回调一起使用
实现这一目标的正确代码是什么?将以下内容作为评论发布;这应该是一个答案,因此我将其添加为社区维基:
问题在于您在regex模式中与
preg\u replace\u callback()
函数一起使用的e
(修饰符)。从正则表达式中删除e
(修饰符)
因此,您的代码看起来很简单:
preg_replace_callback('/&#(\d+);/m', function($m) { return utf8_encode(chr($m[1])); },$source);
问题在于您在
regex
模式中使用的e
(修饰符)
以及preg\u replace\u callback()
函数。请从regex中删除该e
(修饰符)
。因此,您的代码看起来就像是preg_replace_回调('/(\d+);/m',函数($m){return utf8_encode(chr($m[1]));},$source)代码>谢谢你的支持,它成功了。