php读取(打开)csv文件的小例子
时间:2021-07-01 10:21:17
帮助过:22人阅读
//设置UTF-8编码 - setlocale(LC_ALL, 'en_US.UTF-8');
- //csv路径
- $csv_file = "csv/excel.csv";
- //以只读方式打开文件
- $handle = fopen($csv_file, "r");
- //定义结果数组
- $listarr = array();
- //打开csv中一行,并用","分割为数组
- while($data = fgetcsv($handle, 1000, ",")){
- $num = count($data);
- for($i=0; $i<$num; $i++){
- $data[$i] = mb_convert_encoding($data[$i],"UTF-8","UTF-8");
- }// bbs.it-home.org
- $listarr[] = $data;
- }
return $listarr; >>> 更多有关php 生成(导出)csv的内容。 |