ConFoo Montreal 2026: Call for Papers

Voting

: max(two, nine)?
(Example: nine)

The Note You're Voting On

rlazarotto15+dont+spam+me at gmail dot com
4 years ago
Complimenting marcus at synchromedia dot co dot uk comment, you can also do something like this:

<?php

// create a SplFileObject for reading - note that there are no flags
$file = new SplFileObject('/path/to/file', 'r');

// iterate over its contents
while (!$file->eof()) {
// get the current line
$line = $file->fgets();

// trim it, and then check if its empty
if (empty(trim($line))) {
// skips the current iteration
continue;
}
}

While
this may seem like a overkill for such thing, it allows you to do some processing with the empty lines that might come (I had to do this mostly because I needed to count empty lines instead of just skipping them). Since it also trims the line before checking if it's empty, you won't get lines composed only of empty spaces (I don't know if the flags also make it trim the content before checking it).

<< Back to user notes page

To Top