note 70774 added to function.fgetcsv
| From: | php | Date: | Fri, 27 Oct 2006 11:05:22 +0000 |
| Subject: | note 70774 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119181@lists.php.net to get a copy of this message | ||
Re: LEON _AT_ TIM-ONLINE _DOT_ NL
12-Oct-2006 09:47
Very Handy Function, thanks! However I needed to tweak it a bit: (remove the var_dump, store the
info in the big array when using columnheadings and forward $enclosure to the fgetcsv)
<?php
function parse_csv_file($file, $columnheadings = false, $delimiter = ',', $enclosure =
null) {
$row = 1;
$rows = array();
$handle = fopen($file, 'r');
while (($data = fgetcsv($handle, 1000, $delimiter, $enclosure )) !== FALSE) {
if ($columnheadings == true && $row == 1) {
$headingTexts = $data;
}
elseif ($columnheadings == true) {
foreach ($data as $key => $value) {
unset($data[$key]);
$data[$headingTexts[$key]] = $value;
}
$rows[] = $data;
}
else {
$rows[] = $data;
}
$row++;
}
fclose($handle);
return $rows;
} ?>
----
Server IP: 85.116.0.130
Probable Submitter: 83.67.60.250
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit -- https://master.php.net/note/edit/70774
Del: integrated -- https://master.php.net/note/delete/70774/integrated
Del: useless -- https://master.php.net/note/delete/70774/useless
Del: bad code -- https://master.php.net/note/delete/70774/bad+code
Del: spam -- https://master.php.net/note/delete/70774/spam
Del: non-english -- https://master.php.net/note/delete/70774/non-english
Del: in docs -- https://master.php.net/note/delete/70774/in+docs
Del: other reasons-- https://master.php.net/note/delete/70774
Reject -- https://master.php.net/note/reject/70774
Search -- https://master.php.net/manage/user-notes.php