在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}]就可以了。
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php匹配中文汉字,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。