PHP在preg_replace上崩溃

PHP*_*Pst 20 php crash preg-match

我使用以下命令运行以下脚本php.exe:

preg_replace('#(?:^[^\pL]*)|(?:[^\pL]*$)#u','',$string);
Run Code Online (Sandbox Code Playgroud)

或等同物:

preg_replace('#(?:^[^\pL]*|[^\pL]*$)#u','',$string);
Run Code Online (Sandbox Code Playgroud)

如果$string="S"$string=" ?? " 它有效,如果 string='?'它产生?不正确,并且string='??'PHP崩溃.

但它适用于4.4.0 - 4.4.9,5.0.5 - 5.1.6版本.

怎么了 ?

:http://3v4l.org/T3rpV


<?php
$string='??';
echo preg_replace('#(?:^[^\pL]*)|(?:[^\pL]*$)#u','',$string);
Run Code Online (Sandbox Code Playgroud)

输出为5.4.0 - 5.5.0alpha6

Process exited with code 139.
Run Code Online (Sandbox Code Playgroud)

输出为5.2.0 - 5.3.22,5.5.0beta1

 

输出为4.4.0 - 4.4.9,5.0.5 - 5.1.6

?? 
Run Code Online (Sandbox Code Playgroud)

输出为4.3.11,5.0.0 - 5.0.4

Warning: preg_replace(): Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 7 in /in/T3rpV on line 3 
Run Code Online (Sandbox Code Playgroud)

输出为4.3.0 - 4.3.10

Warning: Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 7 in /in/T3rpV on line 3
Run Code Online (Sandbox Code Playgroud)

小智 5

您可以使用替代mb_ereg_replace()函数:

mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8");
echo mb_ereg_replace('#(?:^[^\pL]*)|(?:[^\pL]*$)#u','',$string);
Run Code Online (Sandbox Code Playgroud)


PHP*_*Pst 0

最后解决了这个bug:

\n\n
\n
Output for 4.4.0 - 4.4.9, 5.0.5 - 5.1.6, 5.5.27 - 5.5.33, 5.6.11 - 7.0.4, hhvm-3.6.1 - 3.12.0\n    \xd8\xaf\xd8\xaf\n
Run Code Online (Sandbox Code Playgroud)\n
\n