有一个库可以用PHP编写RFC 4180 CSV文件? [英] Is there a library that can write an RFC 4180 CSV file with PHP?

查看:232
本文介绍了有一个库可以用PHP编写RFC 4180 CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道fputcsv,但根据这个wontfix错误 fputcsv没有正确转义输入,并且由于兼容性原因它的行为将不会被修复。我更喜欢遵守 RFC 4180 的实施,因此Excel和LibreOffice可以全部打开它

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.

我已经尝试搜索一个能正确执行此操作的库,但似乎没有对一个体面的第三方库的一致意见,而是通常建议有缺陷的fputcsv。

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.

推荐答案

看来,每个图书馆在2008年停止发展一些时间。我不知道是什么。这里似乎是热门的选项:

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:

  • PEAR's File_CSV, with zero end-user documentation, as we've come to expect from PEAR. This looks like the expected configuration info, including those for separator and quote.
  • parseCSV seems sane enough
  • PHP CSV Utils is linked quite a bit, though the "new blog" hosting updates is long gone.

我可以'保证任何这些。我恰好住在一个神奇的土地上,我只需要处理Excel生成的CSV文件,永远不会在字段中包含换行符。这让我逃避 fgetcsv / fputcsv ,并且幸运地不知道他们在现实世界中如何破碎。

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.

这篇关于有一个库可以用PHP编写RFC 4180 CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆