Search Webmaster Help and Solution

[RESOLVED] fread fwrite a file containing a <textarea> </textarea>

I want a webpage that can open another webpage, edit the contents and then save the changes.

I can do this using the functions fread and fwrite, however the pages Im trying to edit contain both html and php.

I use fread then put the contents into a <textarea>, the problem is that the files Im editing contain the tag </textarea> so at that point the contents of the file are no longer displayed in the text area - some lines go missing and the rest is displayed outside the textarea.

Ive tried various ideas including stripslashes and htmlentities to no avail.

Code: <?php // set file to read $filename = "testfile.php"; $newdata = $_GET[newdata]; if ($newdata != ) { // open file $fw = fopen($filename, w) or die(Could not open file!); // write to file // added stripslashes to $newdata $fb = fwrite($fw,stripslashes($newdata)) or die(Could not write to file); // close file fclose($fw); } // open file $fh = fopen($filename, "r") or die("Could not open file!"); // read file contents $data = fread($fh, filesize($filename)) or die("Could not read file!"); // close file fclose($fh); // print file contents echo "<h3>Contents of File</h3> <form action=$_SERVER[php_self] method= get > <textarea name=newdata cols=100% rows=500> $data </textarea> <input type=submit value=Change> </form>"; ?> And an excerpt from a testfile.php that causes this problem:

Code: if($_GET[edit]==on){ echo " <center> <br/><br/> <form METHOD=post action=index.php?edit=done&page=".$page."> <textarea name=content cols=90 rows=40>".mysql_result($result,0,content)."</textarea> <br/> <input type=submit value=Save> </form> </center>"; } Thanks for reading. I want a webpage that can open another webpage, edit the contents and then save the changes.

I can do this using the functions fread and fwrite, however the pages Im trying to edit contain both html and php.

I use fread then put the contents into a <textarea>, the problem is that the files Im editing contain the tag </textarea> so at that point the contents of the file are no longer displayed in the text area - some lines go missing and the rest is displayed outside the textarea.

Ive tried various ideas including stripslashes and htmlentities to no avail.

Code: <?php // set file to read $filename = "testfile.php"; $newdata = $_GET[newdata]; if ($newdata != ) { // open file $fw = fopen($filename, w) or die(Could not open file!); // write to file // added stripslashes to $newdata $fb = fwrite($fw,stripslashes($newdata)) or die(Could not write to file); // close file fclose($fw); } // open file $fh = fopen($filename, "r") or die("Could not open file!"); // read file contents $data = fread($fh, filesize($filename)) or die("Could not read file!"); // close file fclose($fh); // print file contents echo "<h3>Contents of File</h3> <form action=$_SERVER[php_self] method= get > <textarea name=newdata cols=100% rows=500> $data </textarea> <input type=submit value=Change> </form>"; ?> And an excerpt from a testfile.php that causes this problem:

Code: if($_GET[edit]==on){ echo " <center> <br/><br/> <form METHOD=post action=index.php?edit=done&page=".$page."> <textarea name=content cols=90 rows=40>".mysql_result($result,0,content)."</textarea> <br/> <input type=submit value=Save> </form> </center>"; } Thanks for reading.

View Complete Thread with Replies

Related Items

Query failed: connection to localhost:3354 failed (errno=111, msg=Connection refused).