PHP file encoding conversion is relatively simple, but it is difficult to transfer Chinese parameters. sometimes it is difficult to know what encoding is, and the result is garbled. This article mainly introduces php automatic identification encoding and conversion to UTF-8 method, need friends can refer to the PHP conversion file encoding is a relatively simple thing, however, when a Chinese parameter is passed during development, sometimes the encoding is unknown, leading to garbled characters. There is a very convenient solution that can automatically identify the encoding and convert it to a UTF-8. The code is as follows:
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;
}