|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41315 file() should support FILE_SKIP_EMPTY_LINES without FILE_IGNORE_NEW_LINES
Submitted: 2007-05-07 16:19 UTC Modified: 2016-06-22 18:00 UTC
Avg. Score:4.5 ± 1.1
Reproduced:23 of 24 (95.8%)
Same Version:10 (43.5%)
Same OS:10 (43.5%)
From: cschneid at cschneid dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 5.2.2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
45 - 43 = ?
Subscribe to this entry?

 [2007-05-07 16:19 UTC] cschneid at cschneid dot com
Currently file() only skips (FILE_SKIP_EMPTY_LINES) when also using      
FILE_IGNORE_NEW_LINES at the same time. I think it would be      
preferable if it would work without that flag too, ignoring lines      
only consisting of a newline.     
diff -u -r1.409. file.c 
--- ext/standard/file.c 23 Feb 2007 16:22:20 -0000      
+++ ext/standard/file.c 7 May 2007 16:17:27 -0000 
@@ -750,6 +750,10 @@ 
                        do { 
+                               if (skip_blank_lines && (p-s == 1) 
&& (*s == eol_marker)) { 
+                                       s = p; 
+                                       continue; 
+                               } 
                                if (PG(magic_quotes_runtime)) { 
                                        /* s is in target_buf which 
is freed at the end of the function */ 
                                        slashed = php_addslashes(s, 
(p-s), &len, 0 TSRMLS_CC); 

Reproduce code:
Input file x:

var_dump(file("x", FILE_SKIP_EMPTY_LINES));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-10 19:43 UTC] theanomaly dot is at gmail dot com
The reason FILE_SKIP_EMPTY_LINES doesn't skip any lines without using it in 
combination with FILE_IGNORE_NEW_LINES is because to PHP the lines still aren't 
empty until they amount to a 0 length string. With the EOL character (or 
characters in the case of CRLF) still a part of the string the lines will remain 
a part of the returned array from file().

However, since this technically doesn't break any BC (given that the 
FILE_SKIP_EMPTY_LINES flag doesn't do anything without FILE_IGNORE_NEW_LINES) I 
don't see why it would be a bad idea to support this when the only thing 
remaining on the line is the EOL.

I've offered to submit this as a feature request instead and will also submit a 
patch for the documentation to clarify this behavior.
 [2016-06-22 18:00 UTC]
-Package: Feature/Change Request +Package: *General Issues
 [2016-06-22 18:00 UTC]
JFTR: the PR had been closed in the meantime without having been
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 20:01:39 2024 UTC