rajbal Posted June 13, 2007 Share Posted June 13, 2007 Hi, When i am saving the below shown html to a text file using php write function, the text file is not the same as the html source. Character " " changes to "Â" and ">" converts to ">".How can i save the below shown html as it is to the text file. Html source to be saved ==================== <div class="secondaryLink bottomMarg2" id="crumbtrail"> <a href="http://www.dev.com/?pageid=searchcomposer&pageregion=header">Home</a> > Search </div> <h1>Composer Search Results For: John</h1> Regards, Raj Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/ Share on other sites More sharing options...
Caesar Posted June 13, 2007 Share Posted June 13, 2007 <?php $str = '<div class="class">'; $html = htmlspecialchars($str); echo $html; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-273585 Share on other sites More sharing options...
rajbal Posted June 13, 2007 Author Share Posted June 13, 2007 Hi Ceaser, What you have sent works if you put the text in the script itself as variable. But in my case i am submitting a form where it has a content: Html source to be saved ==================== <div class="secondaryLink bottomMarg2" id="crumbtrail"> Home > Search </div> <h1>Composer Search Results For: John</h1> ==================================== This content on the process page becomes Html source to be saved ==================== <div class="secondaryLink bottomMarg2" id="crumbtrail"> Home > Search </div> <h1>Composer Search Results For: John</h1> But i want the same text what i have submitted.. Regards, Raj Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274245 Share on other sites More sharing options...
Caesar Posted June 14, 2007 Share Posted June 14, 2007 <?php $str = '<div class="class"> > '; $html = htmlentities($str); echo $html; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274265 Share on other sites More sharing options...
Caesar Posted June 14, 2007 Share Posted June 14, 2007 Tested by submitting via a form: <?php if(isset($_POST['submit'])) { $str = $_POST['mydata']; $html = htmlentities($str); echo $html; //Outputs '<div class="class"> > ' } echo' <form method="post" action="'.$_SERVER['PHP_SELF'].'"> <table> <tr><td><input type="text" name="mydata"></td></tr> <tr><td><input type="submit" name="submit" value="submit"></td></tr> </table> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274275 Share on other sites More sharing options...
rajbal Posted June 14, 2007 Author Share Posted June 14, 2007 You are right it works the way your code is shown.Lemme explain how is my code structure.Here i have a cgi script where teh particular text(<div class="class"> > ) is a hidden input value and i am using method=post for submitting to a process.php script .And in this script while retrieving the submitted value i am not getting the same values which i submitted.Can you guess with this much information where i am doing mistake?? Regards, Raj Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274288 Share on other sites More sharing options...
Caesar Posted June 14, 2007 Share Posted June 14, 2007 In process.php, do some debugging to see how the data looks before it is inserted into the document. <?php print_r($inputxt);exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274291 Share on other sites More sharing options...
rajbal Posted June 14, 2007 Author Share Posted June 14, 2007 Home > Search Composer Search Results For: John This is the result i get... Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274297 Share on other sites More sharing options...
Caesar Posted June 14, 2007 Share Posted June 14, 2007 Right. So you know the variable name/field it is posting from....and you can view the result. Now, can you show the code in process.php where you're inserting into a file? Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274299 Share on other sites More sharing options...
rajbal Posted June 14, 2007 Author Share Posted June 14, 2007 Data received at the process.php is getting changed .Thats why i am getting this issue.I need to get it in the same form as i submitted... Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274300 Share on other sites More sharing options...
rajbal Posted June 14, 2007 Author Share Posted June 14, 2007 <?php print_r($_POST['skip']); $skipline = htmlentities($_POST['skip']); echo $skipline; $myFile = "TestLink.rtf"; $myFilesize= filesize($myFile); if ($myFilesize > 0) { $fh = fopen($myFile, 'a') or die("can't open file"); $skipline=str_replace(array("%26","%27","More >"),array("&","'","More >"),$skipline); fwrite($fh, $skipline); fwrite($fh, "\n===\n"); fclose($fh); }else { $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $skipline); fwrite($fh, "\n===\n"); fclose($fh); } ?> This is the code.. Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274303 Share on other sites More sharing options...
rajbal Posted June 14, 2007 Author Share Posted June 14, 2007 Hi Caesar, Curious if got any success???or do i have to encode the values before submitting the form?If that is the case how i can encode if its a cgi script and shell on it... Quote Link to comment https://forums.phpfreaks.com/topic/55352-how-to-save-and-retrieve-html-in-its-original-form/#findComment-274868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.