Jump to content

Recommended Posts

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 "&nbsp" changes to "Â" and "&gt" 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

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

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>';

?> 

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

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.