Here are the functions that filter the HTML code:
Copy the Code code as follows:
function Ihtmlspecialchars ($string) {
if (Is_array ($string)) {
foreach ($string as $key = = $val) {
$string [$key] = Ihtmlspecialchars ($val);
}
} else {
$string = Preg_replace ('/& (# (\d{3,5}|x[a-fa-f0-9]{4}) |[ a-za-z][a-z0-9]{2,5});)/', ' &\\1 ',
Str_replace (Array (' & ', ' ' ', ' < ', ' > '), Array (' & ', ' "', ' < ', ' > '), $string));
}
return $string;
}
Functions for filtering HTML code under PHP
Copy the Code code as follows:
function HtmlEncode ($string) {
$string =trim ($string);
$string =str_replace ("&", "&", $string);
$string =str_replace ("'", "'", $string);
$string =str_replace ("&", "&", $string);
$string =str_replace ("", "" "", $string);
$string =str_replace ("\" "," "", $string);
$string =str_replace ("<", "<", $string);
$string =str_replace ("<", "<", $string);
$string =str_replace (">", ">", $string);
$string =str_replace (">", ">", $string);
$string =str_replace ("", "", $string);
$string =nl2br ($string);
return $string;
}
The above describes the HTML source PHP filter HTML code functions to improve the security of the program, including the content of HTML source code, I hope the PHP tutorial interested in a friend helpful.