douxiong2738 2013-10-05 20:56
浏览 22

php preg_match为什么它在地球上不起作用?

this is just so bang head on wall situation. this pattern works perfectly in javascript. and i have no idea what to do.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://yugioh.wikia.com/wiki/List_of_Yu-Gi-Oh!_BAM_cards'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$chHtml = curl_exec($ch);
curl_close($ch);
$patt = '/<table class="wikitable sortable card-list">[\s\S]*?<\/table/im'; //////////////this 
preg_match($patt, $chHtml, $matches);

is the problem line

if i make it greedy

[\s\S]*

it works fine but it goes till the last

  • 写回答

1条回答 默认 最新

  • duanmeng1858 2013-10-06 08:36
    关注

    There is nothing wrong with the pattern, the problem is that you need a larger backtrack limit than the default.

    Explaining:

    In regex problems like that always check for errors using the preg_last error().

    If you use it in the specific response from the site you submitted, since this is a resource problem and smaller texts do not raise the error, you will see that you are getting a PREG_BACKTRACK_LIMIT_ERROR.

    Solution:

    To overcome this limit you can raise it with the following in the start of your script:

    ini_set ('pcre.backtrack_limit', 10000000);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致