Maison >développement back-end >tutoriel php >html特殊字符过滤php类
[code] class HtmlFilter { /** * 过滤字符串中的特殊字符 * @static * @param $content * @return string */ public static function filterSpacialHtmlChar($content) { if (empty($content)) { return ''; } $content=self::delAllSpace($content); $content=self::replaceHtmlAndJs($content); return strip_tags($content); } /** * 生成摘要 * @static * @param $content * @param $len * @param string $char * @return string */ public static function getSummary($content,$len=100,$char='UTF-8'){ if(empty($content)){ return ''; } if($len>=mb_strlen($content)){ return self::filterSpacialHtmlChar($content); } // bbs.it-home.org return mb_substr(self::filterSpacialHtmlChar($content),0,$len,$char).'...'; } /** * 去掉 $str中的特殊字符 * @static * @param $document * @return mixed|string */ public static function replaceHtmlAndJs($document) { $document = trim($document); if (strlen($document) ","gt","#62","greater-than sign"); $sh[]=array("?","OElig","#338","latin capital ligature OE"); $sh[]=array("?","oelig","#339","latin small ligature oe"); $sh[]=array("?","Scaron","#352","latin capital letter S with caron"); $sh[]=array("?","scaron","#353","latin small letter s with caron"); $sh[]=array("?","Yuml","#376","latin capital letter Y with diaeresis"); $sh[]=array("?","circ","#710","modifier letter circumflex accent"); $sh[]=array('',"tilde","#732","small tilde"); $sh[]=array("?","ensp","#8194","en space"); $sh[]=array("?","emsp","#8195","em space"); $sh1[]=array("?","thinsp","#8201","thin space"); $sh[]=array("–","ndash","#8211","en dash"); $sh[]=array("—","mdash","#8212","em dash"); $sh[]=array("‘","lsquo","#8216","left single quotation mark"); $sh[]=array("’","rsquo","#8217","right single quotation mark"); $sh[]=array("?","sbquo","#8218","single low-9 quotation mark"); $sh[]=array("“","ldquo","#8220","left double quotation mark"); $sh[]=array("”","rdquo","#8221","right double quotation mark"); $sh[]=array("?","bdquo","#8222","double low-9 quotation mark"); $sh[]=array("?","dagger","#8224","dagger"); $sh[]=array("?","Dagger","#8225","double dagger"); $sh[]=array("‰","permil","#8240","per mille sign"); $sh[]=array("?","lsaquo","#8249","single left-pointing angle quotation mark"); $sh[]=array("?","rsaquo","#8250","single right-pointing angle quotation mark"); $sh[]=array(" |