27

I am aware of fputcsv, but according to this "wontfix" bug fputcsv does not correctly escape input, and its behavior will not be fixed for compatibility reasons. I would prefer an implementation that is compliant with RFC 4180 so Excel and LibreOffice can open it in all cases.

I've tried googling for a library that does this correctly, but there doesn't seem to be a consensus on a decent third party library, instead commonly suggesting the defective fputcsv. I could always roll my own, but I'd prefer not to reinvent the wheel if at all possible.

AlexMax
  • 1,184
  • 13
  • 36

1 Answers1

20

It seems that every library out there stopped development some time in 2008. I'm not sure what's up with that. Here seem to be the popular-ish options:

I can't vouch for any of these. I happen to live in a magical land where I only need to deal with Excel-generated CSV files that will never, ever contain newlines in a field. This lets me get away with fgetcsv/fputcsv and be blissfully ignorant of how they're broken in the real world.

Corey C.
  • 57
  • 2
  • 7
Charles
  • 48,924
  • 13
  • 96
  • 136
  • 5
    I just played around with some of these libs and found that parseCSV excapes " with "" and adds quotes around entries containing commas. PHP CSV Utils doesn't do these things. ParseCSV is also contained in a single file, while PHP CSV Utils is in multiple files and doesn't include itself, so you need lots of require_onces in any file using it. – perilandmishap Mar 08 '12 at 22:56
  • parseCSV currently (September 2015) has uses a lot of memory with huge files (i'm talking about 100MB+). Other than that, it's awesome. – amenthes Sep 08 '15 at 09:13