PHP Filter Functions


PHP Filter Introduction

This PHP filters is used to validate and filter data coming from insecure sources, like user input.


The filter functions are part of the PHP core. There is no installation needed to use these functions.

PHP Filter Functions

PHP: indicates the earliest version of PHP that supports the function.

filter_has_var()Checks if a variable of a specified input type exist5
filter_id()Returns the ID number of a specified filter5
filter_input()Get input from outside the script and filter it5
filter_input_array()Get multiple inputs from outside the script and filters them5
filter_list()Returns an array of all supported filters5
filter_var_array()Get multiple variables and filter them5
filter_var()Get a variable and filter it5


PHP Filters

PHP Filter Functions

ID NameDescription
FILTER_CALLBACKCall a user-defined function to filter data
FILTER_SANITIZE_STRINGStrip tags, optionally strip or encode special characters
FILTER_SANITIZE_STRIPPEDAlias of “string” filter
FILTER_SANITIZE_ENCODEDURL-encode string, optionally strip or encode special characters
FILTER_SANITIZE_SPECIAL_CHARSHTML-escape ‘”<>& and characters with ASCII value less than 32
FILTER_SANITIZE_EMAILRemove all characters, except letters, digits and !#$%&’*+-/=?^_`{|}~@.[]
FILTER_SANITIZE_URLRemove all characters, except letters, digits and $-_.+!*'(),{}|\\^~[]`<>#%”;/?:@&=
FILTER_SANITIZE_NUMBER_INTRemove all characters, except digits and +-
FILTER_SANITIZE_NUMBER_FLOATRemove all characters, except digits, +- and optionally .,eE
FILTER_UNSAFE_RAWDo nothing, optionally strip or encode special characters
FILTER_VALIDATE_INTValidate value as integer, optionally from the specified range
FILTER_VALIDATE_BOOLEANReturn TRUE for “1”, “true”, “on” and “yes”, FALSE for “0”, “false”, “off”, “no”, and “”, NULL otherwise
FILTER_VALIDATE_FLOATValidate value as float
FILTER_VALIDATE_REGEXPValidate value against regexp, a Perl-compatible regular expression
FILTER_VALIDATE_URLValidate value as URL, optionally with required components
FILTER_VALIDATE_EMAILValidate value as e-mail
FILTER_VALIDATE_IPValidate value as IP address, optionally only IPv4 or IPv6 or not from private or reserved ranges