Did you ever wonder how to add the raw html code or other side-scripting language to your web page?

Then, i've got something for you.

Before getting deprecated by W3C, <xmp> tag was used to display the preformatted text (such as the raw codes). However, the tag is still supported by many browser.

Alternate, given to it was <pre> and <code> tag.

<code> tag is used to display a piece of computer code. Thus, for inline codes we'll use the tag.

Since <pre> preserves both spaces and line breaks so for block code we'll use combination of both <pre> and <code> tags, like this <pre><code>.

The main advantage of <xmp> tag was that there was no need for escaping the special character like <,> and & etc.

But inside <pre> or <code> tags, these must be escaped.

Now, we know that escaping is essential, so how you will do it?

Certainly not manually, below some piece of php line escapes all the html special characters for you.
function filter($data)
$data = htmlentities($data);
$data = htmlspecialchars($data);
return nl2br($data);
echo filter($_POST["htmltext"]);
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<textarea type="text" rows="5" cols="50" name="htmltext"></textarea>
<input type="submit" value="submit">

All rights reserved, the content is copyrighted to the author.