here is my csv
column1,column2,column3,column4,column5
column1_row1,column2_row1,column3_row1,column4_row1,column5_row1
column1_row2,column2_row2,column3_row
Can't you just do one fgetcsv
call first to get the headers, and then start a loop to get the rest?
Modified the example found in the manual. It should write out a table with headers and values following.
';
// Get headers
if (($data = fgetcsv($handle, 1000, ',')) !== FALSE)
{
echo ''.implode(' ', $data).' ';
}
// Get the rest
while (($data = fgetcsv($handle, 1000, ',')) !== FALSE)
{
echo ''.implode(' ', $data).' ';
}
fclose($handle);
echo '';
}
?>