preg_match正则表达式找不到匹配项(但它适用于正则表达式101)


preg_match Regex wont find matches (but it works on regex101)

这是我的正则表达式101示例,它有效:https://regex101.com/r/fE6rO9/2(你必须等待几秒钟,因为它很大)

这是我的PHP。

    $content = htmlentities($contentCode);
    /* correct echo when i copy paste it into regex101 */
    echo $content;
    // copy past from regex101
    $re = "/<''/form><table class='"forumline'" width='"100%'" border='"0'" cellspacing='"1'" cellpadding='"0'">(.*)<''/table><table width='"100%'" border='"0'" cellspacing='"0'" cellpadding='"0'">/"; 
    preg_match($re, $content, $matches);
    var_dump($matches);

但是当我运行它时,它会回响:

array (size=0)
  empty

知道问题是什么吗?

这是正则表达式的部分:

"/<''/form><table class='"forumline'" width='"100%'" border='"0'" cellspacing='"1'" cellpadding='"0'">(.*)<''/table><table width='"100%'" border='"0'" cellspacing='"0'" cellpadding='"0'">/"; 

我已经测试了您的正则表达式,如果您删除它似乎可以工作

$content = htmlentities($contentCode);

只需使用:

$content = $contentCode;

笔记:

  1. 请确保您阅读了您无法使用正则表达式解析 [X]HTML
  2. regex的一些替代方案是多姆·多库门或 simplehtmldom