php - Skip the first line of a CSV file -
i trying import csv file. due program use, first row headers skip since i've put own headers in via html. how can code skip first row of csv? (the strpos command cut off first field in rows.)
<?php $row = 1; if (($handle = fopen("ptt.csv", "r")) !== false) { while (($data = fgetcsv($handle, 1000, ",")) !== false) { $num = count($data); $row++; ($c=0; $c < $num; $c++) { if(strpos($data[$c], 'finished') !== false) { $c++; echo "<tr> <td nowrap>" . $data[$c] . "</ td>"; } else{ echo "<td nowrap>" . $data[$c] . "</ td>"; } } } fclose($handle); } ?>
as keeping track of row number anyway, can use continue skip rest of loop first row.
for example, add @ start of while loop (just above $num = count($data)):
if($row == 1){ $row++; continue; } there other ways this, make sure when continue, $row still being incremented or you'll infinite loop!
Comments
Post a Comment