当我试图用以下代码查找一些字符时,我遇到了一个问题:
$str = "统计类型目前分为0日Q统计,月统q计及287年7统1计三7种,如需63自定义时间段,点1击此hell处进入自o定w义统or计d!页面。其他统计:客服工作量统计 | 本周服务统计EXCEL";
preg_match_all('/[\w\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A]/',$str,$match); //line 5
print_r($match);我得到的错误如下:
Warning: preg_match_all() [function.preg-match-all]: Compilation failed: PCRE does not support \L, \l, \N, \U, or \u at offset 4 in E:\mycake\app\webroot\re.php on line 5我不太熟悉reg表达式,也不知道这个error.How,我能解决这个问题吗?谢谢。
发布于 2010-05-10 19:06:27
问题是,PCRE正则表达式引擎不理解通过\uXXXX码点表示字符的unicode -syntax。相反,PCRE引擎使用与u-modifier相结合的\x{XXXX}-syntax:
preg_match_all('/[\w\x{FF10}-\x{FF19}\x{FF21}-\x{FF3A}\x{FF41}-\x{FF5A}]/u',$str,$match);
print_r($match);有关更多信息,请参阅my answer here。
编辑:
$str = "统计类型目前分为0日Q统计,月统q计及287年7统1计三7种,如需63自定义时间段,点1击此hell处进入自o定w义统or计d!页面。其他统计:客服工作量统计 | 本周服务统计EXCEL";
preg_match_all('/[\w\x{FF10}-\x{FF19}\x{FF21}-\x{FF3A}\x{FF41}-\x{FF5A}]/u',$str,$match);
// ^
// |
print_r($match);
/* Array
(
[0] => Array
(
[0] => 0
[1] => Q
[2] => q
[3] => 2
[4] => 8
[5] => 7
[6] => 7
[7] => 1
[8] => 7
[9] => 6
[10] => 3
[11] => 1
[12] => h
[13] => e
[14] => l
[15] => l
[16] => o
[17] => w
[18] => o
[19] => r
[20] => d
[21] => E
[22] => X
[23] => C
[24] => E
[25] => L
)
) */您确定您使用的是u-modifier (参见上面的箭头)?如果是这样,你必须检查你的PHP是否支持u-modifier (在Unix上PHP> 4.1.0,在Windows上> 4.2.3 )。
https://stackoverflow.com/questions/2802074
复制相似问题