欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php下過濾html代碼的函數(shù) 提高程序安全性

 更新時間:2010年03月02日 13:32:23   作者:  
用PHP過濾html里可能被利用來引入外部危險內(nèi)容的代碼。有些時候,需要讓用戶提交html內(nèi)容,以便豐富用戶發(fā)布的信息,當(dāng)然,有些可能造成顯示頁面布局混亂的代碼也在過濾范圍內(nèi)。
以下為過濾HTML代碼的函數(shù):
復(fù)制代碼 代碼如下:

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('&amp;', '&quot;', '&lt;', '&gt;'), $string));
}
return $string;
}


php下過濾HTML代碼的函數(shù)
復(fù)制代碼 代碼如下:

function htmlEncode($string) {
$string=trim($string);
$string=str_replace("&","&",$string);
$string=str_replace("'","'",$string);
$string=str_replace("&amp;","&",$string);
$string=str_replace("&quot;",""",$string);
$string=str_replace("\"",""",$string);
$string=str_replace("&lt;","<",$string);
$string=str_replace("<","<",$string);
$string=str_replace("&gt;",">",$string);
$string=str_replace(">",">",$string);
$string=str_replace("&nbsp;"," ",$string);
$string=nl2br($string);
return $string;
}

相關(guān)文章

最新評論