PHP匹配中文汉字

来源:互联网 发布:java连接phoenix 编辑:程序博客网 时间:2024/04/30 08:32

在java中的汉字匹配是[\u4E00-\u9FA5],想当然的在PHP中使用这个正则后报了如下错误:

Warning: preg_match_all():Compilation failed: PCRE does not support \L, \l, \N{name}, \U, or \u at offset 6 in D:\xampp\htdocs\test\index.php on line 7

后面发现在PHP中\x是表示16进制的。于是将正则改为[\x4E00-\x9FA5],但是还是会报如下错:

Warning: preg_match_all(): Compilation failed: invalid UTF-8 string at offset 9 in
D:\xampp\htdocs\test\index.php on line 7
看来又是正则表达式问题,最后用把正则改成[\x{4E00}-\x{9FA5}]就可以了。

0 0
原创粉丝点击