27

我知道 fputcsv,但根据这个“wontfix”错误fputcsv 不能正确地转义输入,并且出于兼容性原因,它的行为不会被修复。我更喜欢符合RFC 4180的实现,以便 Excel 和 LibreOffice 在所有情况下都可以打开它。

我尝试在谷歌上搜索一个正确执行此操作的库,但似乎对一个体面的第三方库没有达成共识,而是通常建议有缺陷的 fputcsv。我总是可以自己动手,但如果可能的话,我宁愿不要重新发明轮子。

4

1 回答 1

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.

于 2011-03-17T20:02:02.163 回答