Why does this CSV not be parsed with fgetcsv?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 10:23:41

问题


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].";";
  }
} 
?>

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

This is the Running version: Problem with CSV


回答1:


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.

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

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



来源:https://stackoverflow.com/questions/8125523/why-does-this-csv-not-be-parsed-with-fgetcsv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!