Introduction to PHP Filter
PHP filters are used to verify and filter data from unsafe sources (such as user input.
Copy codeThe Code is as follows:
// Remove html tags or encode special characters
Var_dump (filter_var ("
// Url_encoded encoding, excluding or encoding special characters
Var_dump (filter_var ("http: // Chinese", FILTER_SANITIZE_ENCODED ));
// Html Escape Character "" <> & characters with ASCII values smaller than 32.
Var_dump (filter_var ("<A & B # \"> ", FILTER_SANITIZE_SPECIAL_CHARS ));
// Delete All characters except letters, numbers, and! # $ % & '* +-/=? ^ _ '{| }~ @. []
Var_dump (filter_var ("AS $ &> <", FILTER_SANITIZE_EMAIL ));
// Delete All characters except letters, numbers, and $-_. +! * '(), {}|\\^ ~ [] '<> # % ";/? : @ & =
Var_dump (filter_var ("k <>! ", FILTER_SANITIZE_URL ));
// Delete All characters except numbers and +-
Var_dump (filter_var ("123ABC ++", FILTER_SANITIZE_NUMBER_INT ));
// Delete All characters except numbers, +-, and. and eE.
Var_dump (filter_var ("mm., pp", FILTER_SANITIZE_NUMBER_FLOAT ));
// Apply addslashes
Var_dump (filter_var ("aa //'' ", FILTER_SANITIZE_MAGIC_QUOTES ));
// Verify the value in an integer in the specified range
Var_dump (filter_var (20, FILTER_VALIDATE_INT, array ("options" => array ("min_range" => 10, "max_range" => 51 ))));
// If it is "1", "true", "on", and "yes", true is returned. If it is "0", "false", "off ", "no" and "", false is returned. Otherwise, NULL is returned.
Var_dump (filter_var (1, FILTER_VALIDATE_BOOLEAN ));
// Verify the value with a floating point number.
Var_dump (filter_var (222, FILTER_VALIDATE_FLOAT ));
// Verify the URL
Var_dump (filter_var ("http://www.baidu.com", FILTER_VALIDATE_URL ));
// Verify email
Var_dump (filter_var ("abcd@123.com", FILTER_VALIDATE_EMAIL ));
// Verify the IP address
Var_dump (filter_var ("1.1.1.266", FILTER_VALIDATE_IP ));