Problem with Textarea, shows encoded htmls in decoded form

Hello

I have a strange problem with textarea tag. When I load a string which contains encoded html into it, it decodes “encoded htmls” when showing the text. I want the encoded parts to remain encoded.

Anyone can help?

Thank you very much.


<textarea cols=80 rows=20><p>We can use a background picture for web pages instead of
    background color. <BODY> tag in HTML code can be extended to include an
    image file name as the background of the page. Let's assume we have an &quot;image1.gif&quot;
    file and we want to use it as background. Image file must be in the same folder
    as our html file otherwise browser will not be able to find it. (Or you can add
    the file path to the image file name). </p>
  <p>Example 1-3: <span style='font-weight:normal'>page1-3.html</span></p>

  <p><HTML><br>
    <HEAD><br>
    <TITLE>My company web page</TITLE><br>
    </HEAD><br>
    <BODY BACKGROUND=&quot;image1.gif&quot;><br>

    Welcome to our homepage. More text here.<br>
    </BODY><br>
    </HTML></p>

  <palign=center><br>
  <img width=438 height=321 src='images/image008.jpg'></p></textarea>

  • Please see the snapshot of the produced textarea here

As far as i know, if you have printed the text with PHP script (like echo $details) PHP does decode some of the entities automatically. So while showing in the textarea just encode them with htmlentities()

The problem is that even in pure html this thing happens.

If we do a second time encoding using htmlspecialchars it seems the problem will be solved.

But the question is that why the hell html’s textarea should decode (and actually change) something that we give to it?

If you want < to appear on the web page itself, you need to encode the ampersand, resulting in &<


<textarea cols=80 rows=20><p>We can use a background picture for web pages instead of
...
  <p>&amp;lt;HTML&amp;gt;<br>
    &amp;lt;HEAD&amp;gt;<br>
    &amp;lt;TITLE&amp;gt;My company web page&amp;lt;/TITLE&amp;gt;<br>
    &amp;lt;/HEAD&amp;gt;<br>
    &amp;lt;BODY BACKGROUND=&amp;quot;image1.gif&amp;quot;&amp;gt;<br>

    Welcome to our homepage. More text here.<br>
    &amp;lt;/BODY&amp;gt;<br>
    &amp;lt;/HTML&amp;gt;</p>

  <palign=center><br>
  <img width=438 height=321 src='images/image008.jpg'></p></textarea>