Want to parse a CSV file using PHP To parse a CSV file in PHP, the code is as follows. Under fopen(), set the path of the .csv file:
1 2 3 4 5 6 7 8 9 10 11 12 |
$row_count = 1; if (($infile = fopen("path to .csv file", "r")) !== FALSE) { while (($data_in_csv = fgetcsv($infile, 800, ",")) !== FALSE) { $data_count = count($data_in_csv); echo "<p> $data_count in line $row_count: <br /></p>\n"; $row_count++; for ($counter=0; $counter < $data_count; $counter++) { echo $$data_in_csv[$counter] . "<br />\n"; } } fclose(infile); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.