How to display HTML tags as plain text

Viewed 484725

I have an input form on my website where HTML is allowed and I'm trying to add instructions about the use of HTML tags. I'd like the text to

<strong>Look just like this line - so then know how to type it</strong>

But so far all I get is:

Look just like this line - so then know how to type it

How can I show the tags so people know what to type?

11 Answers

The native JavaScript approach -

('<strong>Look just ...</strong>').replace(/</g, '&lt;').replace(/>/g, '&gt;');

Enjoy!

There is another way...

header('Content-Type: text/plain; charset=utf-8');

This makes the whole page served as plain text... better is htmlspecialchars...

Hope this helps...

Related