Php - edit file using another file

hello,

ive used a php script to edit my css and index.php files.


<? 
$myfile="index.php";

if ($btupdate=="UPDATE"){
      $file=fopen($myfile,"w"); 
      $newcontent=stripslashes($newcontent);
      fputs($file,$newcontent); 
      fclose($file); 
      echo "<h3>FILE $myfile HAS BEEN UPDATED</h3>";
}


   if($file=fopen($myfile,"r")) 
   { 
      $linenum=0;
      while(!feof($file)) 
      { 
         $contents.=fgets($file,355); 
         $linenum++;
      } 
      fclose($file); 
   } 
   else 
   { 
      echo("File not Found"); 
   } 

   echo "<title>Edit $myfile</title>";
   echo "<FORM METHOD=\"post\" ACTION=\"".$PHP_SELF."\">";
   echo "<div align=\"center\">";
   echo "<p><FONT size=\"10px\" face=\"Trebuchet MS, Verdana, sans-serif, Arial, Geneva\">Content File : $myfile</font></p>";
   echo "<p><TEXTAREA NAME='newcontent' cols=100 rows=27 class=entri>".$contents."</TEXTAREA>";
   echo "<p><INPUT TYPE=submit NAME='btupdate' VALUE='Update' class=tombol> ";
   echo "<INPUT TYPE=reset VALUE='Reset' class=tombol> ";
   echo "</div>";
   echo "</FORM>";

?>

but my index.php exceed 355 lines. All the remaining lines displayed as html instead of code.
Editing this:

 $contents.=fgets($file,355); 

to any bigger value(>355) doesnt help. It still display for the first 355 lines.

How to modify this