hmvrulz Posted October 8, 2008 Share Posted October 8, 2008 am new to File function in php I have a list in a txt file.. i wanna capture only alternative lines from the txt file. Any suggestions. Thanx in advance Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 8, 2008 Share Posted October 8, 2008 Well, i'd read the lines into an array, set a variable to zero, increment that variable inside a foreach loop and only echo when it's divisible by two: $file = file('path/to/file.txt'); $i = 0; foreach($file as $line){ if($i % 2 == 0){ echo $line.'<br />'; } $i++; } Quote Link to comment Share on other sites More sharing options...
hmvrulz Posted October 8, 2008 Author Share Posted October 8, 2008 Well, i'd read the lines into an array, set a variable to zero, increment that variable inside a foreach loop and only echo when it's divisible by two: $file = file('path/to/file.txt'); $i = 0; foreach($file as $line){ if($i % 2 == 0){ echo $line.'<br />'; } $i++; } Thanx Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.