搜索了好多关于生僻字的替换,结果发现全是千篇一律的iconv…但愿人间少一些人云亦云的人
//自动转UTF-8编码
$str = "鐄";
$encode = mb_detect_encoding($str, ["ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5', 'LATIN1']); //获取字符编码
if ($encode != 'UTF-8') { //不是utf的就按照他的编码变成utf的
$str = mb_convert_encoding($str, 'UTF-8', $encode);
}else{
//这个区间就是utf8的区间了
}
//还得需要判断一下是不是中文...balalalalla
$res = preg_match("/^([\x{4e00}-\x{9fa5}]|[\x{9fa6}-\x{9fef}]|[\x{3400}-\x{4db5}]|[\x{20000}-\x{2ebe0}]){2,15}$/u", $str);
if (!$res) {
echo "不是中文汉字";
}