Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.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
需要帮助在php中替换preg_replace_回调吗?_Php_Regex_Preg Replace_Preg Replace Callback - Fatal编程技术网

需要帮助在php中替换preg_replace_回调吗?

需要帮助在php中替换preg_replace_回调吗?,php,regex,preg-replace,preg-replace-callback,Php,Regex,Preg Replace,Preg Replace Callback,需要帮助解决如下错误 preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in line 601 下面的代码中有错误 $string = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); $string = preg_replace('~&#0*([0-9]+);

需要帮助解决如下错误

preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in line 601
下面的代码中有错误

$string = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
$string = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $string);
我试过了。

$string =  preg_replace_callback('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))',function ($match) {
return ($match[1]);
}, $string);
但还是有这样的错误

Requires argument 2, 'chr(hexdec("\1"))'

如错误所示,PHP版本不再支持
e
修饰符

等价的
preg\u replace\u回调
如下所示:

$string = preg_replace_callback('~&#x([0-9a-f]+);~i', function ($m) {
    return chr(hexdec($m[1]));
}, $string);
注意:正则表达式中的
0*
是不需要的,因为零是由随后的模式捕获的,在捕获组中捕获这些零并不麻烦

但是,因为您使用的是等于或高于5.5(as)的PHP版本,所以您可以依赖
html\u entity\u decode

$string = html_entity_decode($string);

可能重复我累了但不工作。代码在哪里?您在哪里尝试过?您在哪里尝试将匿名函数作为第二个参数传递?不要手动修改;只需将其更新到最新版本。请检查我上面的代码是否出现错误,如需要参数2“chr(hexdec(“\1”)”