#26510 [Opn->Asn]: fgetcsv does not get all lines

From: Date: Fri, 05 Dec 2003 01:15:07 +0000
Subject: #26510 [Opn->Asn]: fgetcsv does not get all lines
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-51715@lists.php.net to get a copy of this message
ID: 26510 Updated by: iliaa@php.net Reported By: thomas303 at web dot de -Status: Open +Status: Assigned Bug Type: Filesystem function related Operating System: Suse Linux 8.2 PHP Version: 4CVS-2003-12-4 -Assigned To: +Assigned To: iliaa New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2003-12-03 16:09:25] thomas303 at web dot de Hi iliaa, one thing, I did was to do a count on the array of fgetcsv. In result it was alwas 18 values per line, so there is less data returned than data existing in the file, i think. best regards thomas ------------------------------------------------------------------------ [2003-12-03 15:37:44] iliaa@php.net fgetcvs() can support multi-line rows, which may explain why a file with X number of lines when read with fgetcvs() would return less lines (but equal amount of total data). If you cannot provide the original cvs file, could you provide an equivalent that can replicate the problem. Without a cvs file it's nearly impossible for us to resolve this problem. ------------------------------------------------------------------------ [2003-12-03 15:24:40] thomas303 at web dot de Hi, me again... in case I consider it correctly, fgetcsv is sometimes - reading and processing a line, and twice jumping to the next line - or ignoring one line and processing the next one. best regards thomas ------------------------------------------------------------------------ [2003-12-03 15:19:27] thomas303 at web dot de Hi, using fget and explode (like written in the script above) $zaehler returns 20967. Using fgetcsv it returns 17861 reading the same file. I am really sorry, I can't provide the file. Best regards Thomas ------------------------------------------------------------------------ [2003-12-03 15:15:57] thomas303 at web dot de #!/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 remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/26510 -- Edit this bug report at http://bugs.php.net/?id=26510&edit=1

« previous php.bugs (#51715) next »