PHP中正则匹配中文的坑


php中正则匹配中文的时候,不能使用 /[\u4e00-\u9fa5]/,而要使用 /[\x{4e00}-\x{9fa5}]/u表示,下面是一个测试例子,需求是如果字符串中包含 < > " ' 中文,则输出正确,否则输出失败
<?php
 header('Content-type: text/html; charset=utf-8');
 $str = "php编程<>\"\'";
 if (preg_match("/[\x{4e00}-\x{9fa5}\<\>\"\']+/u",$str)) {
  print("true");
 } else {
 print("false");
}
?>

参考链接:http://bbs.nasue.com/thread-56722-1-1.html

发布了65 篇原创文章 · 获赞 58 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/AngelLover2017/article/details/84961383
今日推荐