note 42316 deleted from function.tidy-parse-file by nlopess
| From: | nlopess@php.net | Date: | Wed, 12 May 2004 18:29:16 +0000 |
| Subject: | note 42316 deleted from function.tidy-parse-file by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69534@lists.php.net to get a copy of this message | ||
Note Submitter: woodie@worldpac.com
----
I could not find a csv parser, so here is one I created:
$file = file('data.csv');
$cols = explode(",",rtrim(array_shift($file))); // get column headings
array_shift($cols); // delete first (describes nodes)
foreach($file as $row) {
$vals = explode(",",rtrim($row));
$node = array_shift($vals); // first col is node name
foreach($vals as $key => $val) {
$data[$node][$cols[$key]] = $val;
}
}