/** * 检测字符串是否由纯英文,纯中文,中英文混合组成 * * @param string $str * @return int 1:纯英文;2:纯中文;3:中英文混合 */ public function checkString(string $str): int { $m = mb_strlen($str, 'utf-8'); $s = strlen($str); if ($s == $m) { return 1; } if ($s % $m == 0 && $s % 3 == 0) { return 2; } return 3; }