Home > php教程 > php手册 > php自动识别编码转换为UTF-8

php自动识别编码转换为UTF-8

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:08:38
Original
1115 people have browsed it

今天发现一段很好的代码: function characet($data) if( !empty($data) ) $fileType = mb_detect_encoding($data , array(UTF-8,GBK,LATIN1,BIG5)) ; if( $fileType != UTF-8) $data = mb_convert_encoding($data ,utf-8 , $fileType); return $data; 这个

今天发现一段很好的代码:

function characet($data){
  if( !empty($data) ){    
    $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;  
    if( $fileType != 'UTF-8'){  
      $data = mb_convert_encoding($data ,'utf-8' , $fileType);  
    }  
  }  
  return $data;    
}



这个在于传中文参数的时候,由于编码不同,会发生乱码现象,当参数编码不一定是GBK的时候,那就不能都转换编码了
上面的好处是,判断编码,然后转换,和谐了
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template