download2565 2012-04-03 13:12
浏览 55
已采纳

PHP调试preg-replace回调函数

I'm using Exlipse with Xdebug to debug my php codes, which works well. But there is one type of codes I can't debug: callback functions

I'm using preg_replace:

$pc = preg_replace('#\[div(=(.*))?\](.*?)\[/div\]#iuUe', "\bbcode_div('\$2', '\$3')", $_POST["data"]);

which calls the function all right, but the eclipse wont get inside the function while debugging, even with a break point.

How can I make the debugger to get inside that function?

EDIT: I need to use preg_replace.

  • 写回答

2条回答 默认 最新

  • dongposhi8677 2012-04-03 13:21
    关注

    Make sure you're using preg_replace_callback():

    preg_replace_callback('/ /', 'replace', 'this is not a complicated matter');
    
    function replace($t)
    {
       var_dump($t);    // <-- set breakpoint here
    }
    

    This brakes five times before calling var_dump().


    EDIT: Some hackery is required when preg_replace() is used with the e modifier. In this case, setting a breakpoint is not sufficient. You'd have to explicitly tell XDebug to break:

    function replace($t)
    {
       // Production systems might (should) not have this function
       if (function_exists('xdebug_break'))
       {
          xdebug_break();
       }
    
       // Rest of the code...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥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之后自动重连失效