简体   繁体   English

为什么使用 php 从一个非常大的 csv 文件中只读取 1000 条记录?

[英]why only 1000 records are read from a very large csv file using php?

I am just learning to use PHP as a requirement came up at my work and I am trying to figure out why out of 124938 records in my CSV file only 1011 records are being read.我只是在学习使用 PHP 作为我工作中提出的要求,我试图弄清楚为什么我的 CSV 文件中的 124938 条记录中只有 1011 条记录被读取。 Here is the very basic code that I am using.这是我正在使用的非常基本的代码。

<?php
print "<table>\n";
$fp = fopen('STDPRICE_FULL.csv','r') or die("can't open file");
while($csv_line = fgetcsv($fp,1024)) {
  print '<tr>';
  for ($i = 0, $j = count($csv_line); $i < $j; $i++) {
    print '<td>'.$csv_line[$i].'</td>';
  }
  print "</tr>\n";
} 
print '</table>\n';
fclose($fp) or die("can't close file");
?>

When I print the count($csv_line) it shows me 1011 records only.当我打印 count($csv_line) 时,它只显示 1011 条记录。
Now I believe it had something to do with the size of the integer maybe, but I am not sure.现在我相信它可能与整数的大小有关,但我不确定。
Also, I searched ways to increase the size of the integer but PHP seems to handle type conversions on its own.此外,我搜索了增加整数大小的方法,但 PHP 似乎自己处理类型转换。
Can anyone suggest what I can do to read all the lines from the CSV file?谁能建议我可以做什么来读取 CSV 文件中的所有行?

Use that http://dev.mysql.com/doc/refman/5.1/en/load-data.html .使用http://dev.mysql.com/doc/refman/5.1/en/load-data.html

Then work with Database.然后使用数据库。

Use the ParseCSV class.使用 ParseCSV 类。 We've used for really large files with great success.我们已经成功地用于非常大的文件。

ParseCSV Class at GitHub GitHub 上的 ParseCSV 类

It has handled many issues we've had processing CSV files in PHP.它处理了我们在 PHP 中处理 CSV 文件时遇到的许多问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM