Monday, 6 October 2014

What is str_getcsv

array str_getcsv ( string $input [, string $delimiter = ',' [, string $enclosure = '"' [, string $escape = '\\' ]]] )
Parses a string input for fields in CSV format and returns an array containing the fields read.

As the str_getcsv(), unlike to fgetcsv(), does not parse the rows in CSV string, I have found following easy workaround:


= str_getcsv($CsvString, "\n"); //parse the rowsforeach($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.

No comments:

Post a Comment