skip empty lines in files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dannyd
Forum Commoner
Posts: 56
Joined: Wed Jan 23, 2008 11:31 am

skip empty lines in files

Post 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);
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Re: skip empty lines in files

Post by impulse() »

Have you tried anything similar to:

Code: Select all

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