php过滤字符串函数

function StripHTML($string){
$pattern=array ("'<script[^>]*?>.*?</script>'si", "'<style[^>]*?>.*?</style>'si",  "'<[\/\!]*?[^<>]*?>'si",  "'([\r\n])[\s]+'",  "'&(quot|#34);'i",  "'&(amp|#38);'i",  "'&(lt|#60);'i",  "'&(gt|#62);'i",  "'&(nbsp|#160);'i",  "'&(iexcl|#161);'i",  "'&(cent|#162);'i",  "'&(pound|#163);'i",  "'&(copy|#169);'i",  "'&#(\d+);'e");
$replace=array ('', '', "\\1", '', "&", "<", ">", ' ', chr(161), chr(162), chr(163), chr(169), "chr(\\1)");
return preg_replace ($pattern, $replace, $str);
}

posted @ 2015-05-13 10:39  等待出鞘的予  阅读(178)  评论(0编辑  收藏  举报