preg_split("/({{\s*(?:(?!}}).)+\s*}})/s", file_get_contents('data.txt'));
That line makes Apache reset the connection. data.txt
is approximately 12 kB.
What am I doing wrong, can I optimize the regex somehow?
preg_split("/({{\s*(?:(?!}}).)+\s*}})/s", file_get_contents('data.txt'));
That line makes Apache reset the connection. data.txt
is approximately 12 kB.
What am I doing wrong, can I optimize the regex somehow?
Try this regular expression instead:
/({{(?>(?:[^}]|}[^}])+)}})/s
The main improvements:
(?>…)
– atomic grouping to avoid backtracking(?:[^}]|}[^}])+
– no look-around, no non-greedy matching