|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-12-03 13:28 UTC] thomas303 at web dot de
Description:
------------
Hi,
I use the function fgetcsv, but it imported only 17860 of 20900 rows.
Tried \r\n and \n.
I found out, that rows are missing in between of the file, not at the beginning or the end. When I import only these rows (grepped before), everything works fine.
It imports some rows, misses one, imports some and so on.
The error occured the last days without a change in file structure or php. It could be the data itself which leads to the error. I can't reproduce it nor can I send you the file because of data protection reasons.
With fgets and explode everything is fine again. You should check against if fgetcsv works the same way or map fgetcsv to fgets and explode.
Reproduce code:
---------------
$fields=fgetcsv($fp,4096,"|");
with loop and so on.
Expected result:
----------------
$fields=fgetcsv($fp,4096,"|");
should work exactly the same as
$newline=fgets($fp,4096);
$fields=explode("|", $newline);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 07:00:01 2025 UTC |
#!/usr/local/bin/php <?php $file_name="pks.dat"; $fp=fopen($file_name,"r"); while(feof($fp)===False) { // The comment-lines should work instead of fgetcsv. // $new = fgets($fp,4096); // $new_field_values=explode("|",$new); $new_field_values=fgetcsv($fp,4096,"|"); $zaehler++; } fclose ($fp); print $zaehler."\n"; ?>The reason you get unequal amount of lines is because you use an un-escaped delimiter ("), which causes multiple lines to be parsed a single value. There is an unrelated bug in fgetcsv() in PHP 4.X, to which I am testing a patch now.