# Php - edit file using another file

**URL:** <https://forum.kirupa.com/t/php-edit-file-using-another-file/61728>\
**Category:** Uncategorized\
**Created:** [August 21, 2004, 2:28am UTC](https://forum.kirupa.com/t/php-edit-file-using-another-file/61728 "2004-08-21T02:28:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neo\_Geo](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@Neo\_Geo](https://forum.kirupa.com/u/Neo_Geo)\
**Post date:** [August 21, 2004, 2:28am UTC](https://forum.kirupa.com/t/php-edit-file-using-another-file/61728/1 "2004-08-21T02:28:27Z")

</div>

hello,

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

```php

<? 
$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:

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

```

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

How to modify this
