>  기사  >  백엔드 개발  >  html特殊字符过滤php类

html特殊字符过滤php类

WBOY
WBOY원래의
2016-07-25 08:53:58969검색
[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("


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.