function clear_xss2($val, $extratags=array()) {
// version 2 of clear xss2 which allows to keep all valid html tags but removing dangerous html tags
$doc = new DOMDocument();
// load the HTML string we want to strip
libxml_use_internal_errors(true);
$doc->loadHTML($val);
// remove comments
$xpath = new DOMXPath($doc);
foreach ($xpath->query('//comment()') as $comment) {
$comment->parentNode->removeChild($comment);
}