为什么这个CSV不能用fgetcsv解析? [英] Why does this CSV not be parsed with fgetcsv?

查看:126
本文介绍了为什么这个CSV不能用fgetcsv解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法解析格式良好的CSV文件。它可能与编码有关吗?
这是资料来源:

I cannot parse a CSV file which is well formated. Could it be that it has something to do with encoding? This is the Source:

<?php
$handle = fopen ("http://productdata.zanox.com/exportservice/v1/rest/20058589C1721570258.csv?ticket=A3AC91472561713FFB72A266542E9240AFE88CDE05D23B40B28B517606BE5D41&columnDelimiter=;&textQualifier=DoubleQuote&nullOutputFormat=NullValue&dateFormat=dd/MM/yyyy HH:mm:ss&decimalSeparator=comma&gZipCompress=null&id&na&pp&df&ds&im&lk&sn","r");  

while ( ($data = fgetcsv ($handle, 1000, ";")) !== FALSE ) {
  $num = count ($data);
  for ($c=0; $c < $num; $c++) {
    echo $data[$c].";";
  }
} 
?>

我猜,它必须做一些编码。输出是: <{¿{?×(ÄN¾R0;

I guess, it has to do something with encoding. Output is : ‹{¿{?×(ÄN¾R"0;

这是运行版本:
CSV问题

推荐答案

换行符是问题,您有unix字符,但您希望使用Windows风格的换行符
我用给定的CSV文件转换了一个测试。

The newline character is the problem. You have unix chars, but you expect windows-style newlines. I converted an test it with the given CSV file.

您可以使用Windows换行符测试转换的CSV文件:

http://您可以通过autodetection ini_set('auto_detect_line_endings',true)修复此问题

You can test the converted CSV file with windows newlines:
http://pastebin.com/9CK3JMRc

c $ c>
或转换字符串。

You could fix this in the by autodetection ini_set('auto_detect_line_endings', true); or convert the strings.

这篇关于为什么这个CSV不能用fgetcsv解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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