How to display HTML tags as plain text [duplicate]

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?


Solution 1:

Replace < with &lt; and > with &gt;.

Solution 2:

In PHP use the function htmlspecialchars() to escape < and >.

htmlspecialchars('<strong>something</strong>')

Solution 3:

As many others have said, htmlentities() will do the trick... but it will look like shit.

Wrap it up with a <pre> tag and you'll preserve your indentation.

echo '<pre>';
echo htmlspecialchars($YOUR_HTML);
echo '</pre>';