...

View Full Version : Editing file



jabbic
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));
fclose($fp);
}

$fp = fopen('YOURPAGE.php', 'r');
while (!feof($fp)) {
$data .= fgets($fp, 4096);
}
fclose($fp);
echo "
<html>
<head>
<title>PAGE</title>
</head>

<body>
<form action='edit.php' method='post'>
<textarea name='newdata' rows='20' cols='50'>
$data
</textarea>
<br>
<input type='submit' name='submit' value='Submit'>
</form>
</body>
</html>";
?>

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.

jabbic
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.

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

jabbic
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum