Page 1 of 1

skip empty lines in files

Posted: Tue Feb 19, 2008 11:18 am
by dannyd
How can I skip blank lines when reading files in my code below?

while (($filename = readdir($dir)) !== false && $filename != "." && $filename != "..") {

echo '<b>Displaying contents of' . $filename . '</b><BR>';

$file_handle = file_get_contents('./asrunlogs/' . $filename);

// Explodes .txt file into lines (\n)
$Lines = explode("\n",$file_handle);
array_shift($Lines);

Re: skip empty lines in files

Posted: Tue Feb 19, 2008 11:21 am
by impulse()
Have you tried anything similar to:

Code: Select all

 
foreach($Lines as $line) {
  if(!empty($line))
    echo $line;
}