PaulEx10
PaulEx10

Reputation: 155

Outputting HTML into a textbox

I'm trying to output HTML into a textbox and not have it break the textbox.

I'd like it so in the textbox I could have HTML in there, such as spans, h1s, h2s, etc. Each time I try do this the textbox breaks.

enter image description here

I've tried: stripslashes(), decoding the html and re-encoding it. I'm sure there's a simple function that does this but I can't seem to find it.

Any help is appreciated.

Upvotes: 1

Views: 40

Answers (1)

Danny Beckett
Danny Beckett

Reputation: 20806

As Seth suggests, you should use htmlentities().

This way, a string like this:

$str = htmlentities("A 'quote' is <b>bold</b>");

Will be converted to this:

$str = "A 'quote' is &lt;b&gt;bold&lt;/b&gt;";

When outputted to the page, it will show &lt; properly as <, etc.

Upvotes: 1

Related Questions