Show html tag as text

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

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

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?

falsarella

12.1k9 gold badges69 silver badges113 bronze badges

asked Jul 25, 2011 at 13:58

0

Replace with >.

isherwood

54.3k15 gold badges105 silver badges147 bronze badges

answered Jul 25, 2011 at 14:00

DarmDarm

5,4712 gold badges19 silver badges18 bronze badges

4

In PHP use the function htmlspecialchars[] to escape .

htmlspecialchars['something']

answered Jul 25, 2011 at 14:02

acmeacme

14.3k7 gold badges73 silver badges106 bronze badges

0

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

Wrap it up with a

 tag and you'll preserve your indentation.

echo '
';
echo htmlspecialchars[$YOUR_HTML];
echo '
';

answered Mar 25, 2013 at 22:05

JarrodJarrod

9,2015 gold badges57 silver badges72 bronze badges

0

You should use htmlspecialchars. It replaces characters as below:

  • & [ampersand] becomes &
  • " [double quote] becomes " when ENT_NOQUOTES is not set.
  • ' [single quote] becomes ' only when ENT_QUOTES is set.
  • [greater than] becomes >

KetZoomer

2,4863 gold badges14 silver badges37 bronze badges

answered Jul 25, 2011 at 14:00

Luiz DamimLuiz Damim

3,6932 gold badges26 silver badges31 bronze badges

you may use htmlspecialchars[]

Chủ Đề