PHP preg_match_all fails on long lines

Here is my code:

$long = str_repeat('a very long string text', 100); // try changing 100 to 5000

$str = <<<STR
<abc>a short string text</abc>
<abc>$long</abc>
STR;

preg_match_all('@<abc>([^<>]+)</abc>@sU', $str, $matched);

print_r($matched);

And it works fully as expected. However, after you change 100 reps to 5000, run

print_r($matched);

And you only get results for a short line.

My question is how to get preg_match or preg_match_all to work with large text texts (1 MB or more)?

+3
source share
1 answer

You may need to increase the PCRE limits.

http://www.php.net/manual/en/pcre.configuration.php

Edit: But, as ThiefMaster says, don't do this.

+4
source

Source: https://habr.com/ru/post/1774854/


All Articles