View Full Version : Editing file

01-12-2006, 06:07 PM
I've got this script here, it edits the contents of a file. Does anyone know how to make it edit x to y of a file?

// Submission Part
if ($submit) {
$fp = fopen('YOURPAGE.php', 'w');
fwrite($fp, stripslashes($newdata));

$fp = fopen('YOURPAGE.php', 'r');
while (!feof($fp)) {
$data .= fgets($fp, 4096);
echo "

<form action='edit.php' method='post'>
<textarea name='newdata' rows='20' cols='50'>
<input type='submit' name='submit' value='Submit'>

Velox Letum
01-12-2006, 08:07 PM
Well, if you want to replace X with Y, then use str_replace() (http://www.php.net/function.str-replace) on the data.

01-12-2006, 08:24 PM
LMAO, I meant that I want to edit a certiant chunk from the file from like x to y in the file.

01-12-2006, 08:29 PM
Where x and y are what?
Line numbers? Words?

01-12-2006, 08:37 PM
I've got this file yourpage.php but when I edit it with the script a showed you, It edits the whole source. I just want it to edit a certian chunk of the source.