原文地址:http://www.codefans.net/articles/1272.shtml
php自动识别编码,若里面有中文的话,将其转换为UTF-8就最好了,因为中文在Gbk编辑情况情况下,有可能会乱码,这个和客户端和服务端编码都有关系,为了避免乱码,我们可以使用下面的函数将其自动转换为UTF8国际标准编码:
01 |
<?php |
02 |
function characet($data){
|
03 |
if( !empty($data) ){
|
04 |
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
|
05 |
if( $fileType != 'UTF-8'){
|
06 |
$data = mb_convert_encoding($data ,'utf-8' , $fileType);
|
07 |
}
|
08 |
}
|
09 |
return $data;
|
10 |
} |
11 |
?> |