I'm trying to remove any code that a user may have entered in the textarea. I've tried many things, nothing seems to work. Heres the code:
function strip_tags_content($text, $tags = '', $invert = FALSE) {
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0) {
if($invert == FALSE) {
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
}
else {
return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
}
}
elseif($invert == FALSE) {
return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
}
return $text;
}
$message = $_POST['message'];
$message = nl2br($message);
$message = strip_tags($message);
$message = strip_tags_content($message);
$message = htmlentities($message);
Even with all of this, I can still put html tags and have them printed out and run as html. How do I remove all tags?
nl2brafter thestrip_tags.