$fp = fopen('php://stdin', 'r'); $text = ""; while(! feof($fp)) { $text .= fread($fp, 4096); } /** * Allow these tags */ $allowedTags = '
'; /** * Disallow these attributes/prefix within a tag */ $stripAttrib = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup|style|class'; /** * @return string * @param string * @desc Strip forbidden tags and delegate tag-source check to removeEvilAttributes() */ function removeEvilTags($source) { global $allowedTags; $source = preg_replace('/(.*)<\/head>/sm', '', $source); $source = strip_tags($source, $allowedTags); $source = preg_replace('/<(.*?)>/ie', "'<'.removeEvilAttributes('\\1').'>'", $source); $source = preg_replace('//i', '', $source); $source = preg_replace('/<\/b>/i', '', $source); $source = preg_replace('//i', '', $source); $source = preg_replace('/<\/i>/i', '', $source); $source = preg_replace('/^\s*$/', '', $source); $source = preg_replace('/\n\n+/', "\n\n", $source); $source = preg_replace('/^\n/', '', $source); return $source; } /** * @return string * @param string * @desc Strip forbidden attributes from a tag */ function removeEvilAttributes($tagSource) { global $stripAttrib; return trim(preg_replace("/($stripAttrib)=(\"|')?([^\"]+)(\"|')?/", '', stripslashes($tagSource))); } print removeEvilTags($text); ?>