PHP Code:
<?php
//Variables to edit
$filename = "file2edit.txt"; //File to edit
$startmark= "<!--Load from here-->";
$endmark = "<!--Load to here-->";
$source = file_get_contents($filename)
or exit("</br>Problem reading <b>'".$filename."'</b> (check file name)");
$fstart = strpos($source, $startmark)
or exit("</br>Error: Start mark on file not found");
$fstart = $fstart + strlen($startmark);
$fend = strpos($source, $endmark)
or exit("</br>Error: End mark on file not found");
//Split the file
$part1 = substr($source, 0, $fstart);
$part2 = substr($source, $fstart , ($fend-$fstart));
$part3 = substr($source, $fend , (strlen($source)-$fend));
?>
<FORM METHOD="POST" ACTION="save_changes.php">
<P>Edit your file <?=$filename?>:<br>
<TEXTAREA NAME="part2" COLS=80 ROWS=15 WRAP=virtual>
<?=$part2?>
</TEXTAREA></P>
<input type="hidden" name="fname" value="<?=$filename?>">
<input type="hidden" name="part1" value="<?=$part1?>">
<input type="hidden" name="part3" value="<?=$part3?>">
<P><INPUT TYPE="submit" NAME="submit" VALUE="Save Changes"></P>
</FORM>
And the file save_changes.php is
PHP Code:
<?php
IF (ISSET($_POST['fname']))
{
$Newfile = $_POST['part1'] . $_POST['part2'] . $_POST['part3'];
$file = fopen($_POST['fname'],"w");
fwrite($file,$Newfile);
fclose($file);
echo "<br>Changes to file <b>".$_POST['fname']."</b> have been saved";
}
else
{
echo "<br>Nothing done";
}
?>