php自动识别编码,若里面有中文的话,将其转换为UTF-8就最好了,因为中文在Gbk编辑情况情况下,有可能会乱码,这个和客户端和服务端编码都有关系,为了避免乱码,我们可以使用下面的函数将其自动转换为UTF8国际标准编码:
1
2
3
4
5
6
7
8
9
10
11
|
<?php
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
;
}
?>
|
来自淘代码转载请注明