Read data from all rows in a CSV file at once
<?php $file = fopen (' windows_2011_s.csv ', ' R '); while ($data = Fgetcsv ($file)) {//reads a single line of content//print_r ($data) per CSV;//This is an array, to get each data, access the array subscript can $goods_list[] = $data;} Print_r ($goods _list);/* foreach ($goods _list as $arr) {if ($arr [0]!= "") {echo $arr [0]. " <br> "; }} */echo $goods _list[2][0]; Fclose ($file);? >
Reads a row of data from a CSV file
<?phpfunction Get_file_line ($file _name, $line) {$n = 0; $handle = fopen ($file _name, ' R '); if ($handle) {while (!feof ($handle)) {+ + $n; $out = Fgets ($handle, 4096); if ($line = = $n) break; } fclose ($handle); if ($line = = $n) return $out; return false;} Echo get_file_line ("Windows_2011_s.csv", 10);? >
Read CSV file number of rows (line interval)
<?phpfunction get_file_line ( $file _name, $line _star, $line _end) { $n = 0; $handle = fopen ($file _name, "R"); if ($handle) { while (!feof ($handle) ) { ++ $n; $out = fgets ($handle, 4096); if ($line _star <= $n) { $ling [] = $out; } if ($line _end == $n) break; } &nbsP; fclose ($handle); } if ( $line _end== $n) return $ling; return false;} $aa = get_file_line ("Windows_2011_s.csv", 11, 20); //from line 11th to line 20th foreach ($ aa as $bb) { echo $bb. " <br> ";}? >
PHP reads the contents of a CSV file