mb_convert_encoding

最新更新: 2018-07-23 15:00:24 阅读: 25次
1介绍
mb_convert_encoding( $str, $encoding1,$encoding2 )
$str,要转换编码的字符串
$encoding1,目标编码,如utf-8,gbk,大小写均可
$encoding2,原编码,如utf-8,gbk,大小写均可
2实例1

$str='编码';
echo mb_convert_encoding($str, "UTF-8"); //编码转换为utf-8

3实例2

$str='编码';
echo mb_convert_encoding($str, "UTF-8", "GBK"); //已知原编码为GBK,转换为utf-8

4实例3
 $str='编码';
echo mb_convert_encoding($str, "UTF-8", "auto"); //未知原编码,通过auto自动检测后,转换编码为utf-8

应用:
采集时出现乱码,用
$contents = mb_convert_encoding($output, 'utf-8', 'GBK,UTF-8,ASCII'); //加上这行  解决乱码问题