Edit report at https://bugs.php.net/bug.php?id=41315&edit=1
ID: 41315 Comment by: theanomaly dot is at gmail dot com Reported by: cschneid at cschneid dot com Summary: file() should support FILE_SKIP_EMPTY_LINES without FILE_IGNORE_NEW_LINES Status: Open Type: Feature/Change Request Package: Feature/Change Request PHP Version: 5.2.2 Block user comment: N Private report: N New Comment: 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. https://github.com/php/php-src/pull/80 Previous Comments: ------------------------------------------------------------------------ [2007-05-07 16:19:48] cschneid at cschneid dot com Description: ------------ 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. Patch diff -u -r1.409.2.6.2.17 file.c --- ext/standard/file.c 23 Feb 2007 16:22:20 -0000 1.409.2.6.2.17 +++ ext/standard/file.c 7 May 2007 16:17:27 -0000 @@ -750,6 +750,10 @@ do { p++; parse_eol: + 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: a b Code: var_dump(file("x", FILE_SKIP_EMPTY_LINES)); Expected result: ---------------- a b Actual result: -------------- a b ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=41315&edit=1