I want to read data from a text file d.txt. Then create 2 new text files,write a even line in a separate file e.txt and odd in another file o.txt.
<?php
$evenhandler = fopen("e.txt","w");
$oddhandler = fopen("o.txt","w");
$handle = fopen('d.txt', 'r');
while (!feof($handle))
{
$f=fgets($handle);
fwrite($evenhandler,$f);
}
fclose($file);
?>
Actually I didn,t understand how to implement it and according to my code no output was shown on screen.
Performance Tip:
You can even further increase its performance (in case your input file is very big) . You can start with value of $i being as 0 and in the loop just check if it is 0 set it to 1 and vice versa. Then for your if you can just check if i = 1 or i =0 to make a decission. This way you can avoid using modulus operator in every pass and still get same result