php判断字符串编码是否为utf8的函数

来源:互联网 发布:pc 文件夹恢复软件 编辑:程序博客网 时间:2024/06/05 06:21
function is_utf8($word)
{
 if(preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true) {
  return true;
 }else {
  return false;
 }
}
$t = 'wangbin';
//$t = iconv('GB2312','UTF-8',$t)
var_dump(is_utf8($t));
原创粉丝点击