php7.3 pregmatch problem

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>


Answer:

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.

 

Source from

https://ask.csdn.net/questions/948561

相关推荐

暂无评论

微信扫一扫,分享到朋友圈

php7.3 pregmatch problem