Maison  >  Article  >  développement back-end  >  PHP匹配中文汉字

PHP匹配中文汉字

WBOY
WBOYoriginal
2016-08-08 09:20:502116parcourir

在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教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:PHP vs NodejsArticle suivant:YII框架下实现密码修改