fgetcsv double quote problem

Hi,

i’m really stuggling with parsing a csv file and can’t seem to find a solution on the net to my problem.

Referencing the csv data below, I’m trying to get the last element of each csv string, so i want to retreive “GFDDNDB” and “DFADNWB”, but i’m getting “GFDDNDB” and “0”. This is due to the inline double quotes on line 2. I thought that by adding an enclosure parameter to fgetcsv would work, but it just seems to be ignored, am i using it correctly? What am i doing wrong?!

if anyone could help, that would be great.

csv file data:
Field1,548,“605:04”,0,GFDDNDB
Field2,498,“3,408:01”,0,DFADNWB

[php]function CSVImport($file) {

$handle = fopen($file, 'r');     

if (!$handle)         die('Cannot open  file.');     

$rows = array();     //Read the file as csv     

while (($data = fgetcsv($handle, 1000, ',','"')) !== FALSE) {          
	$rows[] =  $data[5]; 
 }      

fclose($handle);      

return $rows;
}
[/php]

I think i’ve sorted my problem, so thought i’d post in case someone else came across a similar issue.

I saved the original csv with ansi encoding rather than unicode and it worked.

Sponsor our Newsletter | Privacy Policy | Terms of Service