I have a problem with fgetcsv() and the enclosure character.
I have a CSV line like this:
"13551","Digitaldruck "Blüte x3" ","gelb-weiss"
I am using fgetcsv() that way:
public function readCSVData($file, $delimiter, $contentDelimiter)
{
$fp = fopen($file, 'r');
$dataResult = array();
while ($data = fgetcsv($fp, WDC_CSV_MAX_LINES, $delimiter, $contentDelimiter))
{
foreach ($data as $key=>$element)
{
$data[$key] = iconv("UTF-8", "ISO-8859-1//IGNORE", $element);
}
$dataResult[] = $data;
}
fclose($fp);
return $dataResult;
}
what I am expecting to get is:
[14] => Array
(
[0] => 13551
[1] => Digitaldruck "Blüte x3"
[2] => gelb-weiss
)
but what I am getting drives me a bit crazy
[14] => Array
(
[0] => 13551
[1] => Digitaldruck Blüte x3""
[2] => gelb-weiss
)
How can I set up my code, that I can use the enclosure character inside the content?
Edit1:
I need to assure, that a quote inside have to escaped with another quote
i.e.:
"13551","Digitaldruck ""Blüte x3"" ","gelb-weiss"
will lead to the right results.