note 101888 modified in function.str-getcsv by danbrown
| From: | danbrown@php.net | Date: | Mon, 17 Jan 2011 14:29:37 +0000 |
| Subject: | note 101888 modified in function.str-getcsv by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175819@lists.php.net to get a copy of this message | ||
As the str_getcsv(), unlike to fgetcsv(), does not parse the rows in CSV string, I have found
following easy workaround:
<?php
$Data = str_getcsv($CsvString, "\n"); //parse the rows
foreach($Data as &$Row) $Row = str_getcsv($Row, ";"); //parse the items in rows
?>
Why not use explode() instead of str_getcsv() to parse rows? Because explode() would not treat
possible enclosured parts of string or escaped characters correctly.
--was--
As the str_getcsv(), unlike to fgetcsv(), does not parse the rows in CSV string, I have found
following easy workaround:
$Data = str_getcsv($CsvString, "\n"); //parse the rows
foreach($Data as &$Row) $Row = str_getcsv($Row, ";"); //parse the items in rows
Why not use explode() instead of str_getcsv() to parse rows? Because explode() would not treat
possible enclosured parts of string or escaped characters correctly.
http://php.net/manual/en/function.str-getcsv.php