php字符编码转utf-8格式

 1 <?
 2 function is_utf8($other) 
 3 { 
 4 if (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$other) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$other) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$other) == true) 
 5 { 
 6 return true; 
 7 } 
 8 else 
 9 { 
10 return false; 
11 } 
12 
13 }
14 ?>
15 
16 
17 
18 <?
19 if(is_utf8($other)==0) 
20 { 
21 $other = iconv("gb2312","UTF-8",$other);
22 }
23 ?>

 

 

posted @ 2013-12-07 10:00  hlb  阅读(376)  评论(0编辑  收藏  举报