note 100593 modified in function.fgetcsv by danbrown
| From: | danbrown@php.net | Date: | Mon, 25 Oct 2010 21:00:23 +0000 |
| Subject: | note 100593 modified in function.fgetcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173451@lists.php.net to get a copy of this message | ||
A simple function to return 2 Dimensional array by parsing a CSV file.
<?php
function get2DArrayFromCsv($file,$delimiter) {
if (($handle = fopen($file, "r")) !== FALSE) {
$i = 0;
while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== FALSE) {
for ($j=0; $j<count($lineArray); $j++) {
$data2DArray[$i][$j] = $lineArray[$j];
}
$i++;
}
fclose($handle);
}
return $data2DArray;
}
?>
--was--
A simple function to return 2 Dimensional array by parsing a CSV file.
function get2DArrayFromCsv($file,$delimiter) {
if (($handle = fopen($file, "r")) !== FALSE) {
$i = 0;
while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== FALSE) {
for ($j=0; $j<count($lineArray); $j++) {
$data2DArray[$i][$j] = $lineArray[$j];
}
$i++;
}
fclose($handle);
}
return $data2DArray;
}
http://php.net/manual/en/function.fgetcsv.php