Issue Bug Closed

#68127CsvUtility method csvToArray does not handle enclosures right

Patrick Broens 07/14/15, 15:52 updated 10/19/17, 21:32

Description

When we have a csv string with enclosures, the first str_getcsv(), which is responsible for exploding the rows, strips off the enclosure of the first row. This is a bug in str_getcsv().

Imagine the next string

"Column A
And a newline", "Column B", "Column C"
"Value", "Value2", "Value 3"

after exploding the rows with str_getcsv(), the output will be

Column A
And a newline, "Column B", "Column C"
Value, "Value2", "Value 3"

The enclosure of the first columns (double quotes) is deleted.

When you have a comma in that cell, the cell will be splitted in two when passing the row string through str_getcsv()

The best solution seems to be to write the string to a temporary file and use fgetcsv().

Reviews 1