in htmlspecialchars function it converts html tags to
& to &
" to "
' to '
< to <
> to >
after convert you can do reverse to decode
<?php
$test="<p><b><a>Test</b></a></p>";
$test = htmlspecialchars($test);
$test = str_replace("<p>", "<p>", $test);
$test = str_replace("<i>", "<i>", $test);
$test = str_replace("<b>", "<b>", $test);
$test = str_replace("</b>", "</b>", $test);
$test = str_replace("</i>", "</i>", $test);
$test = str_replace("</p>", "</p>", $test);
echo $test;
?>