21,893
社区成员




function isGB2312($str) {
$strlen = strlen($str);
for ($i = 0; $i < $strlen; $i ++) {
if (ord(substr($str, $i, 1)) > 0xa0) {
$char = substr($str, $i, 2);
$temp = isGB2312ByChar($char);
$i ++;
if (!$temp)
return false;
}
}
return true;
}
function isGB2312ByChar($code) {
if (strlen($code) == 2 || strlen($code) == 1) {
$code1 = substr($code, 0, 1);
$code2 = substr($code, 1, 1);
// echo '$code1 = ' . ord($code1) . '<br />';
// echo '$code2 = ' . ord($code2) . '<br />';
if (ord($code1) >= 176 && ord($code1) <= 247
&& ord($code2) >= 160 && ord($code2) <= 254)
return 1;
return 0;
} else {
return 0;
}
}
$string = "呵呵";
$flag = isGB2312(mb_convert_encoding($string, "UTF-8", "GB2312"));
文件保存为utf8哈...