开发者

preg_split results in connection reset

开发者 https://www.devze.com 2023-02-02 00:28 出处:网络
preg_split(\"/({{\\s*(?:(?!}}).)+\\s*}})/s\", file_get_contents(\'data.txt\')); That line makes Apache reset the connection. data.txt is approximately 12 kB.
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 开发者_C百科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


Try reading the file into a variable than passing it to preg_split. I think it's file_get_contentsproblem rather thanpreg_split`.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号