Code:
$fp=fopen($file_name, "a+");
fseek($fp, SEEK_SET);
while($str=fgets($fp))
echo $str ."<br>";
fseek($fp, SEEK_SET);
fwrite($fp, $some_text, strlen($some_text));
fclose($fp);
But I don't see why you want to write to a file while opening it for displaying in your window, usualy you let the user see the file, make changes to it, and then uppon submitting the changes you open the file and rewrite it with the contence the user changed it to.