Below is my CSV file. As you can see, it's five columns and on the fifth column there are multiple options also comma separated.
column 1,column 2,column 3,column 4,column 5
value,value,value,value,"value, value2, value3"
val,val,val,val,"opt, opt2, opt3"
Here is the code I'm using the parse the above...
$csvData = file_get_contents('test2.csv');
$csvNumColumns = 5;
$csvDelim = ',';
$csvEnclosure = '"';
$results = array_chunk(str_getcsv($csvData, $csvDelim, $csvEnclosure), $csvNumColumns);
print_r($results);
The output of my print_r is as follows...
Array
(
[0] => Array
(
[0] => column 1
[1] => column 2
[2] => column 3
[3] => column 4
[4] => column 5
value
)
[1] => Array
(
[0] => value
[1] => value
[2] => value
[3] => value, value2, value3
val
[4] => val
)
[2] => Array
(
[0] => val
[1] => val
[2] => opt, opt2, opt3
)
)
As you can see, for some reason this isn't being parsed correctly. I suppose I could explode it by new lines and then again by comma...however, I would like to understand why this isn't working.