Posted in PHP onMarch 02, 2010
以下为过滤HTML代码的函数:
function ihtmlspecialchars($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = ihtmlspecialchars($val); } } else { $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{2,5});)/', '&\\1', str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string)); } return $string; }
php下过滤HTML代码的函数
function htmlEncode($string) { $string=trim($string); $string=str_replace("&","&",$string); $string=str_replace("'","'",$string); $string=str_replace("&","&",$string); $string=str_replace(""",""",$string); $string=str_replace("\"",""",$string); $string=str_replace("<","<",$string); $string=str_replace("<","<",$string); $string=str_replace(">",">",$string); $string=str_replace(">",">",$string); $string=str_replace(" "," ",$string); $string=nl2br($string); return $string; }
php下过滤html代码的函数 提高程序安全性
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@