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);
skip empty lines in files
Moderator: General Moderators
-
impulse()
- Forum Regular
- Posts: 748
- Joined: Wed Aug 09, 2006 8:36 am
- Location: Staffordshire, UK
- Contact:
Re: skip empty lines in files
Have you tried anything similar to:
Code: Select all
foreach($Lines as $line) {
if(!empty($line))
echo $line;
}