htmlentities() is handy for showing tags to the viewer in a browser. It is also handy for security purposes in user input forms if you want to display Javascript hacks in text areas rather than have the hack work and process. It will make the attacker look like an idiot to all that see his/her input since the attack will not work. Or you can simply use the strip_tags() function to remove harmful <script> tags that a user may input.
Our
html_entity_decode() function example will be the same exact code since we really should show one when demonstrating the other since they work in tandem in many applications.

<?php
$original_input = "<em>Hello Suckerbutt!</em>";
$html_encoded = htmlentities($original_input);
echo $html_encoded;
echo "<hr />";
$html_decoded = html_entity_decode($html_encoded);
echo $html_decoded;
?>
<em>Hello Suckerbutt!</em>
Hello Suckerbutt!