php如何给文件转码

2020-08-12 22:45:15

php给文件转码的方法是:首先使用mb_detect_encoding()函数判断文件使用的编码;然后再使用函数mb_convert_encoding()来为文件进行转码即可。

相关函数介绍:

(推荐教程:php教程)

mb_convert_encoding()函数转换字符编码。

mb_detect_encoding() 函数判断字符串使用的编码。

函数语法:

mb_convert_encoding($str,$encoding1,$encoding2);

代码实现:

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;   }
相关文章 大家在看