php HtmlReplace輸入過濾安全函數(shù)
更新時(shí)間:2010年07月03日 12:11:19 作者:
這個(gè)替換函數(shù),是對(duì)用戶輸入的一些安全過濾,防止用戶提交了不安全的代碼。
復(fù)制代碼 代碼如下:
// $rptype = 0 表示僅替換 html標(biāo)記
// $rptype = 1 表示替換 html標(biāo)記同時(shí)去除連續(xù)空白字符
// $rptype = 2 表示替換 html標(biāo)記同時(shí)去除所有空白字符
// $rptype = -1 表示僅替換 html危險(xiǎn)的標(biāo)記
function HtmlReplace($str,$rptype=0)
{
$str = stripslashes($str);
if($rptype==0)
{
$str = htmlspecialchars($str);
}
else if($rptype==1)
{
$str = htmlspecialchars($str);
$str = str_replace(" ",' ',$str);
$str = ereg_replace("[rnt ]{1,}",' ',$str);
}
else if($rptype==2)
{
$str = htmlspecialchars($str);
$str = str_replace(" ",'',$str);
$str = ereg_replace("[rnt ]",'',$str);
}
else
{
$str = ereg_replace("[rnt ]{1,}",' ',$str);
$str = eregi_replace('script','script',$str);
$str = eregi_replace("<[/]{0,1}(link|meta|ifr|fra)[^>]*>",'',$str);
}
return addslashes($str);
}
相關(guān)文章
php命令行(cli)下執(zhí)行PHP腳本文件的相對(duì)路徑的問題解決方法
這篇文章主要介紹了php命令行(cli)下執(zhí)行PHP腳本文件的相對(duì)路徑的問題解決方法,特別是在crontab中運(yùn)行PHP腳本時(shí),肯定會(huì)遇到路徑問題,參照本文方法即可解決,需要的朋友可以參考下2015-05-05
PHP實(shí)現(xiàn)的消息實(shí)時(shí)推送功能【基于反ajax推送】
這篇文章主要介紹了PHP實(shí)現(xiàn)的消息實(shí)時(shí)推送功能,結(jié)合實(shí)例形式分析了php基于反ajax推送實(shí)現(xiàn)的消息實(shí)時(shí)推送前臺(tái)ajax提交、后臺(tái)數(shù)據(jù)處理等相關(guān)操作技巧,需要的朋友可以參考下2018-03-03
php+ajax實(shí)時(shí)輸入自動(dòng)搜索匹配的方法
這篇文章主要介紹了php+ajax實(shí)時(shí)輸入自動(dòng)搜索匹配的方法,實(shí)例分析了兩種實(shí)現(xiàn)方法,是非常實(shí)用的技巧,需要的朋友可以參考下2014-12-12

