php 导入csv文件

            if (($handle = fopen($tmpname, 'r')) !== FALSE) {
            while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
                $isempty = true;
                array_walk($data, function(&$a)use (&$isempty){
                    $a = trim($a);
                    if($a != ''){
                        $t = mb_detect_encoding($a,["UTF-8","GB2312","GBK","BIG5"]);
                        if($t !== false && $t != "UTF-8"){
                            $a = mb_convert_encoding($a, 'UTF-8', $t);
                        }
                        $isempty = false;
                    }
                });
                
                if( $isempty ) continue;
                //......
            }
            fclose($handle);
        }

你可能感兴趣的:(php)