douyanlu7380 2016-06-26 21:07
浏览 76
已采纳

preg_replace_callback():要求参数2成为有效的回调函数

$ent_check = empty($modSettings['disableEntityCheck']) ? 
    array('preg_replace_callback(\'~(&#(\d{1,7}|x[0-9a-fA-F]{1,6});)~e\', \'$func[\\\'entity_fix\\\'](\\\'\\2\\\')\', ', ')') : 
    array('', '');

Warning: preg_replace_callback(): Requires argument 2, '$func['entity_fix']('\2')', to be a valid callback in...

I'm not quite sure what to do here. Any help from someone smarter than I would be greatly appreciated...

  • 写回答

1条回答 默认 最新

  • duanniedang3946 2016-06-26 22:09
    关注

    The First issue here is Intent. Well, the 2nd Argument passed to preg_replace_callback($arg1, $arg2...) is expected to be a Callable. That is why you have that error. It is unclear where you are going with your code but perhaps the code below could throw more light and help you either rethink/clarify your question, intent + goal or revisit your code. Consider this:

    <?php
        $string         = "&#2510 whatever &#5870 again whatever &#7885";
        $modSettings    = array('disableEntityCheck'=>array());
        $func           = array(
            "fix_stuff"     => function($param=20){ echo $param;},
            "do_stuff"      => function($param=10){ echo $param;},
            "entity_fix"    => function($matches ){ return $matches[0] . "YES!!! ";},
        );
    
        $ent_check  = empty($modSettings['disableEntityCheck']) ? array(preg_replace_callback('#\d#', $func['entity_fix'], $string )) :  array('', '');
        var_dump($ent_check);
    
        // DISPLAYS  
        array (size=1)
            0 => string '&#2YES!!! 5YES!!! 1YES!!! 0YES!!!  whatever &#5YES!!! 8YES!!! 7YES!!! 0YES!!!  again whatever &#7YES!!! 8YES!!! 8YES!!! 5YES!!! '
    

    Notice that in the code above, the 2nd Argument passed to preg_replace_callback is a function though passed as a REFERENCE to the 'entity_fix' Key of the array: $func. This was intended to highlight the fact that it is also possible to pass the 2nd Argument in such a manner. It is hoped that this here gives you a little tip to kick off ;-)

    Good Luck!!!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化