#27730 [Opn]: fgetcsv() fails on 2 newlines
| From: | rasmus@php.net | Date: | Sun, 28 Mar 2004 17:03:39 +0000 |
| Subject: | #27730 [Opn]: fgetcsv() fails on 2 newlines | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969359790@lists.php.net to get a copy of this message | ||
ID: 27730
Updated by: rasmus@php.net
Reported By: clemens at gutweiler dot net
Status: Open
-Bug Type: Filesystem function related
+Bug Type: Documentation problem
Operating System: Linux 2.6.3 (and 2.4.20)
PHP Version: 4.3.5
New Comment:
This isn't actually a bug. I have changed this to a documentation
problem as the example on the fgetcsv() page is not very good. The
text description of the function is however correct. You get a
zero-element array for blank lines and FALSE on end of file. So your
code should have a loop like this:
while( ($d = fgetcsv( $fp, 4096, ';' )) !== FALSE )
Previous Comments:
------------------------------------------------------------------------
[2004-03-27 08:50:09] clemens at gutweiler dot net
Description:
------------
fgetcsv() breaks reading when a line has no cdata (eg. \n\n)
Reproduce code:
---------------
<?php
$fn = tempnam( '/tmp', 'test' );
if( $fp = fopen( $fn, 'w' ) ) {
fwrite( $fp, "one;val1\ntwo;val2\n\nthree;val3\n" );
fclose( $fp );
if( $fp = fopen( $fn, 'r' ) ) {
$items = array( );
while( $d = fgetcsv( $fp, 4096, ';' ) ) {
$items[] = $d;
}
fclose( $fp );
var_dump( $items );
}
}
?>
Expected result:
----------------
$items-count of 4
Actual result:
--------------
$item-count of 2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27730&edit=1