需求:过滤字符中所有中文 ,检索出中文的个数
$pattern='/([\x{4e00}-\x{9fa5}]+)/uU';
$text="as234232人3hj呵呵klyuif中abasf国asdf";
$chineseCount=0;
if(preg_match($pattern,$text)){
preg_match_all($pattern,$text,$result);
$chineseCount=count($result[1]);
}
echo $chineseCount;结果
5[Finished in 0.2s]
记录下来,备案