Functions used to filter html code in php improve program security. The following is a function used to filter HTML code: Copy the code as follows: functionihtmlspecialchars ($ string) {if (is_array ($ string) {foreach ($ stringas $ key $ val) {$ string [$ key] ihtm is a function used to filter HTML code:
The code is 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 used to filter HTML code in php
The code is 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 callback code is as follows: function ihtmlspecialchars ($ string) {if (is_array ($ string) {foreach ($ string as $ key = $ val) {$ string [$ key] = ihtm...