note 70957 deleted from function.fgetcsv by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 18:12:01 +0000 |
| Subject: | note 70957 deleted from function.fgetcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155079@lists.php.net to get a copy of this message | ||
Note Submitter: lj at matter dot dk
----
There was a bug with the column headings
function parse_csv_file($file, $columnheadings = false, $delimiter = ',', $enclosure =
"\"") {
$row = 1;
$rows = array();
$handle = fopen($file, 'r');
while (($data = fgetcsv($handle, 1000, $delimiter, $enclosure )) !== FALSE) {
if (!($columnheadings == "false") && ($row == 1)) {
$headingTexts = $data;
} elseif (!($columnheadings == "false")) {
foreach ($data as $key => $value) {
unset($data[$key]);
$data[$headingTexts[$key]] = $value;
}
$rows[] = $data;
} else {
$rows[] = $data;
}
$row++;
}
fclose($handle);
return $rows;
}