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 Link to comment https://forums.phpfreaks.com/topic/127508-how-read-alternative-lines-from-a-txt-files/ 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++; } Link to comment https://forums.phpfreaks.com/topic/127508-how-read-alternative-lines-from-a-txt-files/#findComment-659706 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 Link to comment https://forums.phpfreaks.com/topic/127508-how-read-alternative-lines-from-a-txt-files/#findComment-659742 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.