使用php读取CSV中的随机行分隔符 [英] Random row breaks in CSV read with php

查看:157
本文介绍了使用php读取CSV中的随机行分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取和显示CSV文件的内容。

I am trying to read and display the content of a CSV file. For some reason it bugs out with this file I am trying to read.

这是我的代码。

<?php
if (($handle = fopen("http://testdummies.dk/csv/weird2.csv", "r")) !== FALSE) {

while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
    echo "<pre>";
            print_r ($data);
            echo "</pre>";

}
fclose($handle);
}
?>

我使用丹麦文件,而不是!!

I use a danish CSV file so it uses ; instead of ,!

我已在进行测试http://testdummies.dk/csv/testdups2.php

它生成的前3个数组是正确的,但第4个在单元格我只是不明白为什么。

The first 3 arrays it generates are correct, but the 4th breaks out at "cell" 47. I just cant figure out why. (the file opens fine in excel).

文件在 http://testdummies.dk/csv/weird2.csv

提前感谢。

René

推荐答案

博客文章说,PHP fgetcsv()不能正确处理引用的换行符。他提供了自己的 CsvFileParser 类来解决这个问题。

This blog post says that PHP fgetcsv() doesn't handle quoted newlines properly. He provides his own CsvFileParser class that addresses the problem.

这篇关于使用php读取CSV中的随机行分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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