php里面的编码问题

1 获取当前字符串的编码

$encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5')); 

2 将字符编码改为utf-8

$str_encode = mb_convert_encoding($str, 'UTF-8', $encode);

下面举例子:把一个字符串(utf-8)编码改为gbk

        $file = "C:\Users\Administrator\Desktop\中文.xls";
        $file  = iconv('utf-8', 'gb2312', $file);

        $file = "C:\Users\Administrator\Desktop\中文.xls";
        //自动获取字符串编码
        $encode = mb_detect_encoding($file, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
        $file = mb_convert_encoding($file, 'GB2312', $encode);

参考:http://www.php.net/manual/zh/book.iconv.php

原文地址:https://www.cnblogs.com/fps2tao/p/8016493.html