.*?'si", "']*?>.*?'si", ""/> .*?'si", "']*?>.*?'si", "">

首頁  >  文章  >  後端開發  >  php安全过滤字符串函数

php安全过滤字符串函数

WBOY
WBOY原創
2016-06-20 13:04:21973瀏覽

php安全过滤字符串函数

分享一个php过滤字符串函数,具体代码如下:

function StripHTML($string){<br />$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");<br />$replace=array ('', '', "\\1", '', "&", "<", ">", ' ', chr(161), chr(162), chr(163), chr(169), "chr(\\1)");<br />return preg_replace ($pattern, $replace, $str);<br />}


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn