PHP Write and Read from Text File
<p>I have an issue with writing and reading to text file.</p>

<p>I have to first write from a text file to another text file some values which I need to read again. Below are the code snippets:</p>

<p>Write to text file:</p>

<pre><code>$fp = @fopen ("text1.txt", "r");

$fh = @fopen("text2.txt", 'a+');

if ($fp) {
 //for each line in file
    while(!feof($fp)) {
    //push lines into array
    $thisline = fgets($fp);
    $thisline1 = trim($thisline);

     $stringData = $thisline1. "\r\n";
    fwrite($fh, $stringData);

                  fwrite($fh, "test");

                }
            }
fclose($fp);
fclose($fh);
</code></pre>

<p>Read from the written textfile</p>

<pre><code>$page = join("",file("text2.txt"));
$kw = explode("\n", $page);
for($i=0;$i&lt;count($kw);$i++){

 echo rtrim($kw[$i]);

}
</code></pre>

<p>But, if I am not mistaken due to the "/r/n" I used to insert the newline, when I am reading back, there are issues and I need to pass the read values from only the even lines to a function to perform other operations.</p>

<p>How do I resolve this issue? Basically, I need to write certain values to a textfile and then read only the values from the even lines.</p>

<p>Thanks In Advance</p>
