how do you print every other line of a text file

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
nevets04
Forum Newbie
Posts: 1
Joined: Sun Dec 20, 2009 10:54 pm

how do you print every other line of a text file

Post by nevets04 »

I need a code that prints every other line of a text file.
I.E
a text file contains:
hello
0
there
0
I just want
hello
there
to be displayed
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: how do you print every other line of a text file

Post by MichaelR »

Code: Select all

 
  $file = file_get_contents('index.php');
 
  $file = str_replace("\n0", "\n", $file);
 
  echo $file;
 
Post Reply