PHP判断一段字符串是不是utf8编码的函数
PHP #utf8 #字符串 #函数2012-05-10 21:02
这个函数也常用,哈。
function yige_isUTF8($str){
$length = strlen($str);
for($i=0; $i<$length; $i++) {
$high = ord($str{$i});
if(($high == 0xC0) || ($high == 0xC1)) {
return false;
} elseif($high < 0x80) {
continue;
} elseif($high < 0xC0) {
return false;
} elseif($high < 0xE0) {
if(++$i >= $length) return true;
elseif(($str{$i}&"\xC0") == "\x80") continue;
} elseif($high < 0xF0) {
if(++$i >= $length) {
return true;
} elseif(($str{$i}&"\xC0") == "\x80") {
if(++$i >= $length) return true;
elseif(($str{$i}&"\xC0")=="\x80") continue;
}
}elseif($high < 0xF5) {
if(++$i >= $length) {
return true;
} elseif(($str{$i}&"\xC0") == "\x80") {
if(++$i >= $length) {
return true;
} elseif(($str{$i}&"\xC0") == "\x80"){
if(++$i >= $length) return true;
elseif(($str{$i}&"\xC0") == "\x80") continue;
}
}
}
return false;
}
return true;
}相关文章
- PHP获取访问者IP的函数 2012/05/10
- PHP获取目录的md5值的函数 2012/05/10
- PHP淘宝商品num_iid批量生成淘宝客链接的函数 2012/05/09
- PHP函数is_uploaded_file用法 2012/05/09
- PHP传值/传引用/传地址的区别 2012/05/09
- php面试常见问题及答案 2012/05/09
- PHP比较GET/POST 2012/05/09
- PHP的memory_limit限制修改方法 2012/05/08
- php执行事务mysql实例 2012/05/07
- PHP加密解密迅雷/Flashget/QQ旋风等下载地址 2012/05/07