I am having a problem using a CSV file uploaded via a PHP form. Here is the code:
$row = 1; if (($handle = fopen($_FILES['csv']['tmp_name'], "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); }
The only problem is that when polling the $data variable, the contents of the CSV file are written in one line, and not in several lines. As a result, I get an array of 228 column values.
Why is this? My PHP script does not detect newline correctly? If so, is it possible to correct this behavior?
php csv
Martin bean
source share