Home >Backend Development >PHP Tutorial >replace php HtmlReplace input filtering security function

replace php HtmlReplace input filtering security function

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 08:43:121093browse

Copy code The code is as follows:


// $rptype = 0 means to replace only html tags
// $rptype = 1 means to replace html tags while removing consecutive whitespace characters
// $rptype = 2 means to replace html Tags remove all whitespace characters at the same time
// $rptype = -1 means to replace only html dangerous tags
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','wcriスpt',$str);
$str = eregi_replace("<[/]{0, 1}(link|meta|ifr|fra)[^>]*>",'',$str);
}
return addslashes($str);
}

The above introduces the replace php HtmlReplace input filtering security function, including the content of replace. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn