|  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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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
 [2024-07-11 11:35 UTC] chris1058wright at outlook dot com
I was actually reading your article and found some really interesting information. The thing is quite clear that I just want to thank for it. (
 [2024-07-13 07:27 UTC] Victoria476Huff at outlook dot com
Great post. It was much needed. Love your simplistic style of explanation. (
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 04:01:30 2024 UTC