PHP filtering the HTML code that submits the form may have code that is exploited to introduce externally dangerous content. For example, sometimes a user submits a form that contains HTML content, but this may cause the Display page layout to be cluttered and need to be filtered.
Method One:
Copy Code code as follows:
Get Post Data
function Postget ($str, $post =0)
{
Empty ($str) die (' Para is null '. $str '! '): ';
if ($post)
{
if (GET_MAGIC_QUOTES_GPC ())
{
Return Htmlspecialchars (Isset ($_post[$str])? $_post
[$str]: ');
}
Else
{
Return Addslashes (htmlspecialchars isset ($_post[$str))?
$_post[$str]: ");
}
}
Else
{
if (GET_MAGIC_QUOTES_GPC ())
{
Return Htmlspecialchars (Isset ($_get[$str])? $_get[$str]: ');
}
Else
{
Return Addslashes (htmlspecialchars isset ($_get[$str))?
$_get[$str]: ");
}
}
}
Method Two:
Copy Code code as follows:
function uhtml ($STR)
{
$farr = Array (
"/\s+/",//filter Excess blank
Filtering <script> etc. may introduce malicious content or maliciously change the display layout of the code, if you do not need to insert flash, etc., you can also add <object> filter
"/< (\/?) (script|i?frame|style|html|body|title|link|meta|\?| \%) ([^>]*?) >/isu ",
"/(<[^>]*) on[a-za-z]+\s*= ([^>]*>)/isu",//filter JavaScript on event
);
$tarr = Array (
" ",
"<\1\2\3>",//If you want to clear the unsafe label directly, leave this blank
"\1\2",
);
$str = Preg_replace ($farr, $tarr, $STR);
return $str;
}
Very practical way, I hope to be helpful to everyone