Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Bug #1191 File::readLine() stops on blank lines
Submitted: 2004-04-13 04:17 UTC
From: ieure at php dot net Assigned:
Status: Bogus Package: File
PHP Version: Irrelevant OS: Debian Linux
Roadmaps: (Not assigned)    

 [2004-04-13 04:17 UTC] ieure at php dot net
Description: ------------ When readLine() comes to an empty line in a text file, it stops. Reproduce code: --------------- while ($line = File::readLine('file')) { print $line; } compare with: $fp = fopen('file', 'r'); while ($line = fgets($fp, 1024)) { print $line; } fclose($fp); Expected result: ---------------- The while loop should continue until all lines in 'file' have been read and returned. Actual result: -------------- The while loop stops at the first empty line in 'file'


 [2004-04-13 18:57 UTC] richard at phpguru dot org
Your code is at fault, not the package.
 [2004-05-19 08:02 UTC] ieure at php dot net
In what way is my code at fault? The File documentation does not indicate any methods to either determine the number of lines in a file, nor to determine if there are lines left to be read.
 [2004-06-03 14:31 UTC] mike
Because while treats 0, null, '' and so on as false. You should use while(false !== $line = File::readLine()) HTH