dongyan7851 2019-07-19 11:54
浏览 318
已采纳

php7.3正则表达式出错了[重复]

I am using simple_html_dom.inc.php for url extractor. The codes are working normaly without problem. But i am getting the following Warning from PHP7.3

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in 1387

You can see the error line in this link: Error Line 1387

if (!preg_match("/^[\w-:]+$/", $tag)) {
    $node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until('<>');
    if ($this->char==='<') {
        $this->link_nodes($node, false);
        return true;
    }
    if ($this->char==='>') $node->_[HDOM_INFO_TEXT].='>';
    $this->link_nodes($node, false);
    $this->char = (++$this->pos<$this->size) ? $this->doc[$this->pos] : null; // next
    return true;
}

Do you have a solution for this problem? Thanks in advance.

</div>
  • 写回答

1条回答 默认 最新

  • dongmei8511 2019-07-19 11:56
    关注

    PHP 7.3 upgraded from PCRE to PCRE2. Which is much more strict on regular expressions. For example, you need to escape - between square brackets. And this is the problem in you regex.

    Changing it to /^[\w\-:]+$/ should solve your problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探