Ищу библиотеку которая разрешает только определенные теги и определенные атрибуты. Самому писать лень. (strip_tags атрибуты не проверяет если вдруг кто решит напомнить) Пока что нашел вот это. Может есть что то более навороченное? PHP: <?php function stripUnwantedTagsAndAttrs($html_str){ $xml = new DOMDocument(); //Suppress warnings: proper error handling is beyond scope of example libxml_use_internal_errors(true); //List the tags you want to allow here, NOTE you MUST allow html and body otherwise entire string will be cleared $allowed_tags = array("html", "body", "b", "br", "em", "hr", "i", "li", "ol", "p", "s", "span", "table", "tr", "td", "u", "ul"); //List the attributes you want to allow here $allowed_attrs = array ("class", "id", "style"); if (!strlen($html_str)){return false;} if ($xml->loadHTML($html_str, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD)){ foreach ($xml->getElementsByTagName("*") as $tag){ if (!in_array($tag->tagName, $allowed_tags)){ $tag->parentNode->removeChild($tag); }else{ foreach ($tag->attributes as $attr){ if (!in_array($attr->nodeName, $allowed_attrs)){ $tag->removeAttribute($attr->nodeName); } } } } } return $xml->saveHTML(); } ?>
пурифаер бери и всё, только не забудь, что он требует всё-всё возможное указыать заранее, ничего не забывать.