Coder Perfect

[duplicate] How to show HTML tags as plain text


I have an HTML-enabled input form on my website, and I’m trying to add instructions on how to use HTML tags. I’d like the text to read like this:

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

But all I’ve gotten so far is:

Look just like this line, and you’ll be able to type it.

What is the best way to display the tags so that people know what to type?

Asked by user517593

Solution #1

Replace ‘with’ with ‘with’ and ‘with’ with ‘with’.

Answered by Darm

Solution #2

To escape and > in PHP, use the htmlspecialchars() method.


Answered by acme

Solution #3

htmlentities(), as many others have stated, will do the trick… but it will look like trash.

You can keep your indentation by wrapping it with a pre> tag.

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

Answered by Jarrod

Solution #4

HTMLspecialchars should be used. It replaces the following characters:

Answered by Luiz Damim

Solution #5

htmlspecialchars can be used ()

$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;

Answered by Nikunj K.

Post is based on