Home  >  Article  >  php教程  >  php函数mb_detect_encoding自动识别编码并自动转换成utf8的方法

php函数mb_detect_encoding自动识别编码并自动转换成utf8的方法

WBOY
WBOYOriginal
2016-06-06 20:11:011195browse

php中有一个自动识别编码的函数mb_detect_encoding(),下面的代码是探测文章编码并自动转换成utf8的方法 //自动识别编码并自动转换成utf8 /* 爱推吧 http://ituibar.com */ function characet($data){ if(!empty($data)){ $fileType=mb_detect_encoding($date

php中有一个自动识别编码的函数mb_detect_encoding(),下面的代码是探测文章编码并自动转换成utf8的方法

//自动识别编码并自动转换成utf8
 /*
 爱推吧 http://ituibar.com
 */
 function characet($data){
 if(!empty($data)){
 $fileType=mb_detect_encoding($date,array('utf-8','GBK','LATIN1','BIG5'));
 if($fileType !='utf-8'){
 $data=mb_convert_encoding($data, 'utf-8',$fileType) ;
 }
 }
 return $date;
 }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn