Converting file encoding in PHP is a relatively simple matter, but when passing Chinese parameters during development, sometimes you don’t know what encoding it is, resulting in garbled characters. Here is a very convenient solution that automatically recognizes the encoding and converts it to UTF-8. The specific code is as follows:
Copy code The code is as follows:
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;
}
http://www.bkjia.com/PHPjc/788614.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788614.htmlTechArticlePHP converting file encoding is a relatively simple matter, but when passing Chinese parameters during development, sometimes it is not possible to I know what encoding it is, but the result is garbled characters. Here is a...