编写代码如下:
header('Content-type: text/html; charset=utf-8');
$str = "在士大夫了sdfsdfcxvzv一截";
$pa = '/[\x{4e00}-\x{9fa5}]/siu';
preg_match_all($pa, $str, $r);
$count = count($r[0]);
echo "当前的字符串中,共有 $count 个汉字";
if($count>10)
{
//如果汉字数量大于10,你的代码
}
?>