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);
作者:Wicub
免责声明:文章、笔记等仅供分享、探讨、参考等学习之用,因此造成的任何后果概不负责。(如有错误、疏忽等问题,欢迎指正、讨论,谢谢)
本文版权归作者和博客园共有,欢迎转载,但请务必在文章页面明显位置给出原文连接,谢谢配合。