PHP读取csv文件

<?php    
        
         //取数据
        $f_d = file_get_contents('tpl_import_info.csv');
        $f_d = iconv('gbk', 'utf-8', $f_d);
        file_put_contents('tpl_import_info.csv',$f_d);
        setlocale(LC_ALL,'zh_CN.UTF-8');   //解决fgetcsv处理中文失败的问题
        $hl = fopen('tpl_import_info.csv','r');
        $row_i = 0;
        $data = $total = array();
        while ($file_data = fgetcsv($hl)) {
            ++$row_i;
            $name   = $file_data[0];
            $adress = $file_data[1];
            $phone  = $file_data[2];
      
            $data['name'] = $name;
            $data['adress'] = $adress;
            $data['phone'] = $phone;
            $total[]=$data;
           }
         
        fclose($hl);
        var_dump($total);

 

posted @ 2013-09-12 18:36  午时的海  阅读(360)  评论(0编辑  收藏  举报