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

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!!!

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效