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

 

posted @ 2017-12-10 11:35  与f  阅读(201)  评论(0编辑  收藏  举报