Exalto Posted December 16, 2006 Share Posted December 16, 2006 Hey.Can somebody help me with this script? I have 2 pages. First one is a page with a form which shows a source code of .htm file. Second file just writes to a file. If I edit the code and submit form, it should save modifications to the .htm file. The problem is: when I save the changes, all " and ' characters change to /" and /' .How can I save the file as it is written in the textbox? Here is a source code of the main file:<form id="form1" name="form1" method="post" action="write.php"><?php$lines = file('content.htm');$html = implode('', file('content.htm'));echo' <textarea name="contents" cols="80" rows="40" wrap="off">' .$html. '</textarea> ' ;?>And the file (write.php) which writes to the .htm file:<?php$content = $_POST['contents'];$File = "content.htm";$a = htmlentities($content);$b = html_entity_decode($a);$Handle = fopen($File, 'w'); fwrite($Handle, $b);fclose($Handle); ?>Thank You! ;D Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/ Share on other sites More sharing options...
fert Posted December 16, 2006 Share Posted December 16, 2006 $content=stripslashes($content); Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/#findComment-142632 Share on other sites More sharing options...
Exalto Posted December 16, 2006 Author Share Posted December 16, 2006 Oh Yeah! Thank you. You solved my problem.I am very beginner of php coding :DOne more question. How can I put all this to one file? If I make a function which writes to a file, how can I call it from submit button press? Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/#findComment-142636 Share on other sites More sharing options...
fert Posted December 16, 2006 Share Posted December 16, 2006 You can't call a PHP function when the submit button is pressed like in javascript you have to put the function on another page and set the action attribute of the <form> tag to that page. Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/#findComment-142637 Share on other sites More sharing options...
trq Posted December 16, 2006 Share Posted December 16, 2006 [code]<form method="post"><?php $lines = file('content.htm'); $html = implode('', file('content.htm')); echo' <textarea name="contents" cols="80" rows="40" wrap="off">' .$html. '</textarea> ' ;?><input type="submit"><?php if (isset($_POST['submit'])) { $content = stripslashes($_POST['contents']); $File = "content.htm"; $a = htmlentities($content); $b = html_entity_decode($a); $Handle = fopen($File, 'w'); fwrite($Handle, $b); fclose($Handle); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/#findComment-142638 Share on other sites More sharing options...
Exalto Posted December 16, 2006 Author Share Posted December 16, 2006 It doesn't modify changes i make. It preserves the old source code when I submit the form. Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/#findComment-142645 Share on other sites More sharing options...
trq Posted December 16, 2006 Share Posted December 16, 2006 Sorry, you need.[code]<input type="submit" name="submit">[/code] Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/#findComment-142647 Share on other sites More sharing options...
Exalto Posted December 16, 2006 Author Share Posted December 16, 2006 Now it works but I don't see the changes in textarea after I press submit. It takes old source there. But if I refrest the page I see the changes. How can I refresh the textarea after the submit button is pressed? Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/#findComment-142648 Share on other sites More sharing options...
fert Posted December 16, 2006 Share Posted December 16, 2006 http://www.phpfreaks.com/quickcode/Redirect/532.php Link to comment https://forums.phpfreaks.com/topic/30916-i-need-help-with-this-small-code/#findComment-142656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.