php HtmlReplace输入过滤安全函数

2018-09-07 21:33

阅读:214

  复制代码 代码如下:
// $rptype = 0 表示仅替换 html标记
// $rptype = 1 表示替换 html标记同时去除连续空白字符
// $rptype = 2 表示替换 html标记同时去除所有空白字符
// $rptype = -1 表示仅替换 html危险的标记
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}(linkmetaifrfra)[^>]*>,,$str);
}
return addslashes($str);
}


评论


亲,登录后才可以留言!