欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php HtmlReplace输入过滤安全函数

程序员文章站 2023-11-09 23:15:04
复制代码 代码如下: // $rptype = 0 表示仅替换 html标记 // $rptype = 1 表示替换 html标记同时去除连续空白字符 // $rptype...
复制代码 代码如下:

// $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}(link|meta|ifr|fra)[^>]*>",'',$str);
}
return addslashes($str);
}