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

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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?