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