Web pages are made up of HTML code, so if you post or write some HTML code in a web pages, a browser would generally consider them normal code. Instead of showing them as they are literally, they have become part of the underlying HTML structure of that page.
Now how to address this problem and display HTML code and HTML tags correctly in a web page as the page content?
The answer is, use HTML entities.
HTML entities are a way to encode special HTML characters such as < and > into literal characters that cannot be interpreted by browsers as HTML code. Refer to the most common HTML entities conversion table below:
- ‘&’ (ampersand) becomes ‘&‘
- ‘"’ (double quote) becomes ‘"‘
- ”’ (single quote) becomes ‘'‘
- ‘<‘ (less than) becomes ‘<‘
- ‘>’ (greater than) becomes ‘>‘
Therefore, to display HTML code as they are and show them to your web site visitors, write the special characters such as < and > in HTML entities. For example,
<h2>Beautiful town</h2>
Has to be written:
<h2>Beautiful town</h2>
There are of course handy tools you can use to make these conversions much easier. PHP has a function, htmlentities() that accepts normal HTML code and converts them into HTML entities. You can also rely on online tools to make that happen.
<h1>
The time is:
</h1>
<br>
<table bordercolor="#FFCC00" border="1">
<tr>
<td>
<div id="clock" class="clock">
What are you doing?
you can put whatever code in here you want.
or xml code, i guess whatever that has to get escaped with htmlentities will work.
can’t ask my why tho, cause i don’t know. it just works. its voodoo.
damn it knew it i cant put html in there any ways.
try <pre><xmp> with html code here </xmp></pre>
As far as I know, <xmp> has been deprecated.
Thanx its working fine …
Pingback: PHP: setcookie() with HttpOnly Option to Prevent XSS (Cross Site Scripting) Attacks
@bruce lim –
Thank You !!
You almost solved my headache. Nice work. . . 🙂 🙂
this is of no use Damn it
That’s great bruce worked a treat for me.
Nice one. Thanks.
Great. Thanks.
Pingback: Facebook Landing Pages « fruitfulcommunications
very nice post. thanks for your valuable information.
Good, Thanks