我使用php.exe
运行了以下脚本
preg_replace('#(?:^[^\pL]*)|(?:[^\pL]*$)#u','',$string);
或其等价物:
preg_replace('#(?:^[^\pL]*|[^\pL]*$)#u','',$string);
如果是$string="S"
或$string=" ذذ "
,它就可以工作;如果是string='ذ'
,它就会生成不正确的�
;如果string='ذذ'
PHP崩溃了,它就会崩溃。
但它适用于4.4.0 - 4.4.9,5.0.5 - 5.1.6版本。
出什么问题了?
<?php
$string='دد';
echo preg_replace('#(?:^[^\pL]*)|(?:[^\pL]*$)#u','',$string);
5.4.0 - 5.5.0alpha6的
输出
进程已退出,代码为139。
5.2.0 - 5.3.22,5.5.0beta1 4.4.0 - 4.4.9,5.0.5 - 5.1.6输出
دد
4.3.11、5.0.0 - 5.0.4的输出
警告: preg_replace():编译失败: PCRE不支持第3行/ in /T3rpV中偏移量为7的\L、\l、\N、\P、\p、\U、\u或\X
4.3.0 - 4.3.10的输出
警告:编译失败: PCRE不支持第3行上/ in /T3rpV中偏移量为7的\L、\l、\N、\P、\p、\U、\u或\X
发布于 2016-03-28 19:08:42
最后,bug被解决了:
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دد的
输出
发布于 2013-03-25 13:32:17
您可以使用替代的mb_ereg_replace()函数:
mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8");
echo mb_ereg_replace('#(?:^[^\pL]*)|(?:[^\pL]*$)#u','',$string);
发布于 2013-03-29 22:08:23
也许这会有所帮助:
这些属性通常仅在使用"--enable-unicode- properties“编译PCRE时才可用
http://docs.php.net/manual/en/regexp.reference.unicode.php#96479
https://stackoverflow.com/questions/15608203
复制相似问题