PHP打开CSV文件
- //设置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 $data[$i] = mb_convert_encoding($data[$i],"UTF-8","UTF-8");
- }
- $listarr[] = $data;
- }
-
- return $listarr;
复制代码
|