作为程序员一定要保持良好的睡眠,才能好编程

php获取字符中中文字符的个数

发布时间:2019-03-28


需求:过滤字符中所有中文 ,检索出中文的个数


$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]



记录下来,备案