dou7851 2010-12-20 10:50
浏览 46
已采纳

foreach和preg_match对大量数据不能正常工作

I have to files, one is full of keywords sequences (~20k lines), the other is full of regular expression (~2.5k).

I want to test each keyword with each regexp and print the one that matches. I tested my files and that makes around 22 750 000 tests. I am using the following code :

$count = 0;
$countM = 0;
foreach ($arrayRegexp as $r) {
    foreach ($arrayKeywords as $k) {
        $count++;
        if (preg_match($r, $k, $match) {
            $countM++;
            echo $k.' matched with keywords '.$match[1].'<br/>';
        }
    }
}
echo "$count tests with $countM matches.";

Unfortunately, after computing for a while, only parts of the actual matches are displayed and the final line keeping the counts never displays. What is even more weird is that if I comment the preg section to keep only the two foreach and the count display, everything works fine.

I believe this is due to an excessive amount of data to be processed but I would like to know if there is recommendations I didn't follow for that kind of operations. The regular expressions I use are very complicated and I cannot change to something else.

Ideas anyone?

  • 写回答

2条回答 默认 最新

  • douzhannao5357 2010-12-20 11:04
    关注

    Increase execution time

    usethis line in .htaccess

    php_value max_execution_time 80000
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料