【问题标题】:"Warning: preg_replace_callback(): Requires argument 2, '&#x;', to be a valid callback" ; PHP Error“警告:preg_replace_callback():需要参数 2,'&#x;',才能成为有效的回调”; PHP 错误
【发布时间】:2019-02-08 10:16:38
【问题描述】:

设置一个应该在图像上放置广告的应用程序,我在运行代码时遇到了这个 WordPress 错误,尝试修复这个问题是令人沮丧的一周。

function cwali_json_encode_utf8callback($matches){
    return html_entity_decode('&#x' . $matches[1] . ';', ENT_COMPAT, 'UTF-8');
}
function cwali_json_encode_utf8($json)
{
    return preg_replace_callback('/\\\\u(\w{4})/', cwali_json_encode_utf8callback($matches), json_encode($json));
}

我希望它可以工作,但它给了我以下错误:警告:preg_replace_callback(): Requires argument 2, '', to be a valid callback。

如果有人能提出解决方案,那就太棒了,非常感谢!

【问题讨论】:

  • 需要传递函数名,不要马上调用函数。

标签: php html json function


【解决方案1】:

在您的电话中

preg_replace_callback('/\\\\u(\w{4})/', cwali_json_encode_utf8callback($matches), json_encode($json));

您调用该函数而不是传递回调函数,因此它的返回值作为参数传递。试试

preg_replace_callback('/\\\\u(\w{4})/', 'cwali_json_encode_utf8callback', json_encode($json));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    • 1970-01-01
    • 2011-07-28
    • 2017-11-29
    • 1970-01-01
    相关资源
    最近更新 更多