不带引号的CSV不与fgetcsv一起使用 [英] CSVs without quotes not working with fgetcsv

查看:134
本文介绍了不带引号的CSV不与fgetcsv一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过PHP解析用户上传的CSV文件,但无法正常工作。

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

我已上传了多个格式正确的CSV文件然而,我有很多用户试图导入从Excel导出的CSV文件,他们有问题。我把这些文件与我的比较,并注意到Excel文件都缺少引号。除此之外,它们是相同的。如果我打开它并保存它与Open Office,没有做任何更改在所有它工作。所以我相当肯定它与报价相关。

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.

我的问题是;如何读取这些格式不正确的CSV?

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

更新:找到原因

Mac版的Excel。在使用fgetcsv之前,您应该这样做:

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);


推荐答案

这是特定于Mac版本的Excel。在使用fgetcsv之前,您应该这样做:

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);

这篇关于不带引号的CSV不与fgetcsv一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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