1
2<?php
3$row = 1;
4if (($handle = fopen("test.csv", "r")) !== FALSE) {
5 while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
6 $num = count($data);
7 echo "<p> $num fields in line $row: <br /></p>\n";
8 $row++;
9 for ($c=0; $c < $num; $c++) {
10 echo $data[$c] . "<br />\n";
11 }
12 }
13 fclose($handle);
14}
15?>
16
17
1 $csvFile = file('../somefile.csv');
2 $data = [];
3 foreach ($csvFile as $line) {
4 $data[] = str_getcsv($line);
5 }
1<?php
2ini_set('auto_detect_line_endings',TRUE);
3$handle = fopen('/path/to/file','r');
4while ( ($data = fgetcsv($handle) ) !== FALSE ) {
5 //process the array in $data
6 var_dump($data);
7}
8ini_set('auto_detect_line_endings',FALSE);