首页 > 后端开发 > php教程 > html特殊字符过滤php类

html特殊字符过滤php类

WBOY
发布: 2016-07-25 08:53:58
原创
982 人浏览过
[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("


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板