First we recommend filter_sanitize_string, filter_sanitize_string filter to remove or encode unnecessary characters.
This filter removes data that is potentially harmful to the application. It is used to strip tags and remove or encode unwanted characters.
name: "string"
id-number: 513
Possible options or flags:
filter_flag_no_encode_quotes - This flag does not encode quotes
filter_flag_strip_low - remove characters with ascii value below 32
filter_flag_strip_high - remove characters with ascii value above 32
filter_flag_encode_low - encode characters with ascii value below 32
filter_flag_encode_high - encode characters with ascii value above 32
filter_flag_encode_amp - Encode & character as &
*/
$var="bill gates";
var_dump(filter_var($var, filter_sanitize_string));
/*
The second function strip_tags
The strip_tags() function strips html, xml and php tutorial tags.
Grammar
strip_tags(string,allow)
*/
echo strip_tags("hello world!");
//hello world!
function uh($str)
{
$farr = array(
"/s+/",
//Filter out excess whitespace
"/<(/?)(script|i?frame|style|html|body|title|link|meta|?|%)([^>]*?)>/isu",
//Filter
To add filtering of
"/(<[^>]*)on[a-za-z]+s*=([^>]*>)/isu",
//Filter the on event of web page special effects
);
$tarr = array(
" ",
"<123>", //If you want to directly clear unsafe tags, you can leave it blank here
"12",
);
$str = preg_replace( $farr,$tarr,$str);
}
For more details, please check: http://www.bKjia.c0m/phper/19/70dd2a905e74cefc9be9c0f17268dadc.htm
http://www.bkjia.com/PHPjc/629724.html