php-simple-html-dom-parser icon indicating copy to clipboard operation
php-simple-html-dom-parser copied to clipboard

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

Open sami-42 opened this issue 2 years ago • 6 comments

preg_match(): Compilation failed: invalid range in character class at offset 4 in \simple_html_dom.php on line 1378

Hey anybody knows why this problem occured? Can anybody give the fix to this bug?

sami-42 avatar Mar 31 '22 17:03 sami-42

  • \simple_html_dom.php on line 1378 from "/^[\w-:]+$/" to "/^[\w\-:]+$/";
  • \simple_html_dom.php on line 679 from $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is"; to $pattern = "/([\w\-:\*]*)(?:\#([\w\-]+)|\.([\w\-]+))?(?:\[@?(!?[\w\-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";

this is from php 7.3 update from PCRE to PCRE2 (https://php.watch/versions/7.3/pcre2)

nitadan18 avatar Apr 14 '22 15:04 nitadan18

When I tried updating this application, it keeps on getting the incorrect lines for one specific website, even upon deletion of the full application and reacquiring it with another "composer update" in the root folder of the website. However, for other specific websites, it has the corrected lines above. It obtains version 1.5.2 on both ocassions. I have absolutely no idea why this isn't obtained correctly on some websites whereas it is on others, does anyone know why?

Edit: It happens because some websites are installed differently. Or rather, its CMS. When installing through composer, the CMS has no control over the applications provided by all dependencies, but it can do adjustments within its own core, which means it can correctly update the code in when unpacking its zip. This information for me doesn't help me much, other than re-assuring me a future update of the CMS shouldn't overwrite the corrections suggested by creative3x

patrickkasie avatar Apr 26 '22 12:04 patrickkasie

maybe, i not sure, try to fork repository (how to - https://stackoverflow.com/questions/13498519/how-to-require-a-fork-with-composer).

nitadan18 avatar Apr 27 '22 09:04 nitadan18

any update???

arcanisgk avatar Jan 12 '23 19:01 arcanisgk

Doesn't look like it. Just keep using the solution provided by nitadan18, or use the fix provided by rdmpage (Click the mention)

patrickkasie avatar Jan 23 '23 10:01 patrickkasie

I've used this alternative in PHP 8.2, installing:

composer require paquettg/php-html-parser

Using:

use PHPHtmlParser\Dom;

$dom = new Dom;
$dom->loadFromFile('tests/data/big.html');

Or

use PHPHtmlParser\Dom;

$dom = new Dom;
$dom->loadStr('<div class="all"><p>Hey bro, <a href="google.com">click here</a><br /> :)</p></div>');

More details: https://packagist.org/packages/paquettg/php-html-parser

anayarojo avatar Apr 01 '24 03:04 anayarojo