Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to parse CSV files uploaded by the user through PHP, but it's not working properly.

I've uploaded several properly formatted CSVs and it worked fine, however; I have many users trying to import CSV files exported from Excel and they are having problems. I've compared the files to mine and noticed that the Excel files all lack quotes around the entries. Aside from that, they are identical. If I open it and save it with Open Office, without making any changes at all it works. So I'm fairly certain it's related to the quotes.

My question is; how do I read these improperly formatted CSVs?

UPDATE: Cause has been found!

This is specific to the Mac version of Excel. Line breaks are handled differently on Macs for some arbitrary reason, so before using fgetcsv, you should do this;

ini_set('auto_detect_line_endings',TRUE);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
336 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is specific to the Mac version of Excel. Line breaks are handled differently on Macs for some arbitrary reason, so before using fgetcsv, you should do this;

ini_set('auto_detect_line_endings',TRUE);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...