Skip to content

Conversation

alexandre-daubois
Copy link
Member

@alexandre-daubois alexandre-daubois commented Aug 1, 2025

Fix #18120

Allows to use FILE_SKIP_EMPTY_LINES without FILE_IGNORE_NEW_LINES:

$test_file = __DIR__ . "/file_skip_empty_lines.tmp";

$test_data = "First\n\nSecond\n\n\nThird\n";
file_put_contents($test_file, $test_data);

$lines = file($test_file, FILE_SKIP_EMPTY_LINES);
var_dump($lines);

/**
array(3) {
  [0]=>
  string(6) "First
"
  [1]=>
  string(7) "Second
"
  [2]=>
  string(6) "Third
"
}
*/

@alexandre-daubois
Copy link
Member Author

Friendly ping @DanielEScherzer @nielsdos as you participated on the issue 🙂

@nielsdos
Copy link
Member

I'll play with this tomorrow or so. Note that this is fixing long standing behaviour, so targeting 8.5/master is likely more appropriate.

@DanielEScherzer
Copy link
Member

^ what @nielsdos said about not targeting 8.3, but wearing my release manager hat I don't think 8.5 is appropriate

@nielsdos
Copy link
Member

<?php
$test_file = __DIR__ . "/file_skip_empty_lines.tmp";

$test_data = "\r";
file_put_contents($test_file, $test_data);
$lines = file($test_file, FILE_SKIP_EMPTY_LINES);
var_dump($lines);

$test_data = "\r\r";
file_put_contents($test_file, $test_data);
$lines = file($test_file, FILE_SKIP_EMPTY_LINES);
var_dump($lines);

produces:

array(1) {
  [0]=>
" string(1) "
}
array(0) {
}

which seems incorrect to me. Can you explain whether this is the desired behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FILE_SKIP_EMPTY_LINES only works with FILE_IGNORE_NEW_LINES

3 participants