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
How read Alternative lines from a TXT files
Moderator: General Moderators
Re: How read Alternative lines from a TXT files
The simplest would be to just read two lines at a time, eg:
Hope this helps
Code: Select all
<?php
$oddLines = $evenLines = array();
$fp = fopen('myfile.txt','r'(;
while( ($line = fgets($fp, 2048)) ) {
$oddLines[] = $line;
$evenLines[] = = fgets($fp, 2048);
}
fclose($fp);
// $oddLines now contains lines 1,3,5...
// $evenLines now contains lines 2,4,6...
?>
Re: How read Alternative lines from a TXT files
Thanxmchaggis wrote:The simplest would be to just read two lines at a time, eg:
Code: Select all
<?php $oddLines = $evenLines = array(); $fp = fopen('myfile.txt','r'(; while( ($line = fgets($fp, 2048)) ) { $oddLines[] = $line; $evenLines[] = = fgets($fp, 2048); } fclose($fp); // $oddLines now contains lines 1,3,5... // $evenLines now contains lines 2,4,6... ?>
Hope this helps