1

I have a code that saves (html code) plus (some text) in mysql from textarea. I then take the text from the mysql and display it under the textarea. The thing is if I save the code

<div style="color:red">Hello</div> 

in mysql and then display it, I see Hello in red, but I want to see the actual

<div style="color:red">Hello</div>

to appear under the textarea. I hope you understand my problem.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
gbd
  • 213
  • 1
  • 11

3 Answers3

0

so when you've grabbed the data from the database you want to actually display the html, rather than the page rendering the html?

if so just use the php function htmlentities();

Hazonko
  • 1,025
  • 1
  • 15
  • 30
0

You can use the xmp element, see What was the tag used for. It has been in HTML since the beginning and is supported by all browsers. Specifications frown upon it, but HTML5 CR still describes it and requires browsers to support it (though it also tells authors not to use it, but it cannot really prevent you).

Everything inside xmp is taken as such, no markup (tags or character references) is recognized there, except, for apparent reason, the end tag of the element itself, .

Otherwise xmp is rendered like pre.

When using “real XHTML”, i.e. XHTML served with an XML media type (which is rare), the special parsing rules do not apply, so xmp is treated like pre. But in “real XHTML”, you can use a CDATA section, which implies similar parsing rules. It has no special formatting, so you would probably want to wrap it inside a pre element:

<![CDATA[
This is a demo, tags will
appear literally.
<div style="color:red">Hello</div>
]]>

you can refer this ans : https://stackoverflow.com/a/16785992/3000179

Community
  • 1
  • 1
Nithin
  • 5,470
  • 37
  • 44
0

If you want to do on browser level, you can follow the steps :

  1. Replace the & character with &amp;
  2. Replace the < character with &lt;
  3. Replace the > character with &gt;
  4. Optionally surround your HTML sample with <pre> and/or <code> tags.

Hope this helps.

Prashant Bhujbal
  • 427
  • 6
  • 14