0

I have a csv file that contains double quotes. when I read it using php fgetcsv(), the fields contain quotation will retrun null:

while(($data=fgetcsv($handle,5000,'|'))!==false){
    echo $data[0];
}

and the csv file may look like this

25" H x 8" W |15" H x 5" W
17.5" H x 9" W | 5" H x 12" W

Could anybody give me some advices?

CharlesDou
  • 347
  • 1
  • 7
  • 16

1 Answers1

2

fgetcsv() defaults to using a " as an enclosure character, but you can change this to another different character (e.g. a tilde ~) that isn't used anywhere in your data; then the " won't be misinterpreted

while(($data=fgetcsv($handle,5000,'|','~'))!==false){
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • See, here comes the strange thing. I did what you just said but it didn't work. But if I remove all the white spaces after the quotes, it will be fine, even if I don't make changes like you said. I am totally confused. – CharlesDou Jan 28 '14 at 20:50
  • I just figured out why. I use "Open Office" to make csv files, and it turns out that the software automatically convert white spaces into some random character. That's why it works ok when I removes the white spaces. Thank you for your reply, it makes sense. – CharlesDou Jan 28 '14 at 21:28