htmlentities() does not remove html tags; it convers special characters such as "&" into the appropriate HTML string "&"
To remove HTML and PHP code from input text, use strip_tags() or a regular expression function.
function cleanbody($body)
{
// first protect <g> smileys
$body = str_replace("<g>", "<g>", $body);
// clean out all illegal html
$body = strip_tags($body,'b,i,br,p,a');
if (!get_magic_quotes_gpc())
$body = addslashes($body);
$body = str_replace("\r\n\r\n", "\n<P>", $body);
return $body;
}
This considers blank lines to be paragraph enders and inserts a P tag.