简体   繁体   中英

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. 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.
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.
Can anyone suggest what I can do to read all the lines from the CSV file?

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

Then work with Database.

Use the ParseCSV class. We've used for really large files with great success.

ParseCSV Class at GitHub

It has handled many issues we've had processing CSV files in PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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