PHP Filter function

Introduction to PHP Filter

PHP filters are used to validate and filter data from non-secure sources, such as user input.


Filter function is part of the core of PHP. No installation is required to use these functions.

PHP Filter function

PHP : Indicates the earliest version of PHP that supports this function.

function description PHP
filter_has_var () Check if a variable of the specified input type exists. 5
filter_id () Returns the ID number of the specified filter. 5
filter_input () Get input from outside the script and filter. 5
filter_input_array () Get multiple inputs from outside the script and filter them. 5
filter_list () Returns an array containing all supported filters. 5
filter_var_array () Get multiple variables and filter them. 5
filter_var () Get a variable and filter it. 5

PHP 5 Predefined Filter Constants

ID name description
FILTER_CALLBACK Call a user-defined function to filter the data.
FILTER_SANITIZE_STRING Remove tags, remove or encode special characters.
FILTER_SANITIZE_STRIPPED "String" Alias for the filter.
FILTER_SANITIZE_ENCODED URL_encode string, removing or encoding special characters.
FILTER_SANITIZE_SPECIAL_CHARS HTML escape character '"<>& 以及 ASCIICharacters with a value less than 32.
FILTER_SANITIZE_EMAIL Delete all characters except letters, numbers, and !#$%&'*+_/=?^_`{|}~@.[]
FILTER_SANITIZE_URL Delete all characters except letters, numbers, and $ __. +! * '(),{}|\^~[]`<>#%";/?:@&=
FILTER_SANITIZE_NUMBER_INT Remove all characters except numbers and + _
FILTER_SANITIZE_NUMBER_FLOAT Erase all characters except numbers, + _ and., eE
FILTER_UNSAFE_RAW No filtering, removal or encoding of special characters.
FILTER_VALIDATE_INT Verify the value as an integer.
FILTER_VALIDATE_BOOLEAN Validate the value as a boolean option. If "1"、"true"、"on "and" yes ", returns TRUE. If it is" 0 "," false "," off "," no ", and" ", returns FALSE. Otherwise returns NULL.
FILTER_VALIDATE_FLOAT Verify the value as a floating point number.
FILTER_VALIDATE_REGEXP Validates the value against regexp, a Perl-compatible regular expression.
FILTER_VALIDATE_URL Validate the value as a URL.
FILTER_VALIDATE_EMAIL Verify the value as an e_mail address.
FILTER_VALIDATE_IP Validates the value as an IP address, limited to IPv4 or IPv6 or not from a private or reserved range.