views:

111

answers:

2

In a database, I have the text <b>ISBOLD</b><i>isitalic</i>

How do I do that if I pull out this string, I will see

ISBOLD isitalic

and not

<b>ISBOLD</b><i>isitalic</i>

A: 

There are a couple of ways:

  1. You basically have to convert the special characters into the entity references.
    That means changing < to &lt; and > to &gt; etc.. In PHP there is a function which does this for you called htmlentities

  2. Wrap that output in an <xmp> tag.

Option one is probably the better method.

nickf
Isn't converting < to < going the opposite direction being asked for?
Frank Schwieterman
This is correct why was this downvoted?
Darknight
I think it's a bit of "lost in translation" in the question. The way I read it, he's echoing out a string, and the browser is displaying it as HTML, whereas he wants to see the string in plain text. Converting a HTML string to HTML shouldn't be a problem..?
nickf
A: 

Just echo it! (if it's in PHP anyway)

Shadi Almosri
+1 just print it, the browser will do the job.
Aif