Page 1 of 1

parse every other line

Posted: Fri Aug 26, 2005 9:30 am
by Daisy Cutter
I have this code that I am using to display some quotes on a page:

Code: Select all

<ul id="quotesul">
<?php
$file = "quotes.txt";
$Array = file($file);
foreach ($Array as $key => $val) {
echo "<li>";
echo $val;
echo "</li>";
} 
?>
</ul>
quotes.txt is done for every line right now, but it looks very messy. I want to make it easier to read by putting a space in between every quote, but then of course I get empty <li>'s.

I want to know how to parse every other line (starting with 1) so that it skips the empty lines. I know that might not be the only way, another might be just ignoring lines that contain only EOF or something. Ideas?

Thanks. :wink:

Re: parse every other line

Posted: Fri Aug 26, 2005 9:55 am
by neophyte
how bout this?

Code: Select all

<ul id="quotesul">
<?php
$file = "quotes.txt";
$Array = file($file);
foreach ($Array as $key => $val) {
if(!empty($val)){
 echo "<li>";
       echo $val;
  echo "</li>";
}
} 
?>
</ul>

Posted: Fri Aug 26, 2005 11:05 am
by Daisy Cutter
neophyte you led me in the right direction
your fix didn't work but this did:

Code: Select all

<ul id="quotesul"> 
<?php 
$file = "quotes.txt"; 
$Array = file($file); 
foreach ($Array as $key => $val) { 
if($val!=="\n"){ 
echo "<li>"; 
echo $val; 
echo "</li>"; 
} } 
?>

Posted: Fri Aug 26, 2005 11:09 am
by neophyte
Glad you found a solution. :D