php获取csv数据无乱码

<?php

//获取csv数据
    function csvencode($file){
        if(!is_file($file['tmp_name'])){
            return;
        }
        $handle=fopen($file['tmp_name'],'r');

$content = fread($handle, filesize($file['tmp_name']));
        $content = convert2utf8($content);

$data=explode("\n",$content);

$i=1;
        $arr=array();
        foreach($data as $o){

if(!ctype_space($o) && !empty($o)){

$arr[$i]=explode(',',$o);
                $i++;
            }

}

return $arr;

}

//转换为utf8编码
    function convert2utf8($content)
    {

mb_detect_order("UTF-8, GBK, ISO-8859-1"); //探测顺序
        $encoding = mb_detect_encoding($content);//获取编码
        if ($encoding && strtolower($encoding) !== 'utf-8') {
            $content = iconv($encoding, 'UTF-8//IGNORE', $content);
        }
        return $content;
    }

上一篇:python webdriver 显示等待-自动登录126邮箱,添加联系人


下一篇:asp.net mvc @Html.Partial @Html.Action @Html.RenderPartial @Html.RenderAction区别