FREE Web Template Download
HTML CSS JAVASCRIPT SQL PHP BOOTSTRAP JQUERY ANGULARJS TUTORIALS REFERENCES EXAMPLES Blog
 

PHP 5 Filter Functions


PHP Filter Introduction

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


Installation

As of PHP 5.2.0, the filter functions are enabled by default. There is no installation needed to use these functions.


Runtime Configurations

The behavior of these functions is affected by settings in php.ini:

Name Description Default Changeable
filter.default Filter all $_GET, $_POST, $_COOKIE, $_REQUEST and $_SERVER data by this filter. Accepts the name of the filter you like to use by default. See the filter list for the list of the filter names "unsafe_raw" php-INI_PERDIR
filter.default_flags Default flags to apply when the default filter is set. This is set to filter-FLAG_NO_ENCODE_QUOTES by default for backwards compatibility reasons NULL php-INI_PERDIR

PHP 5 Filter Functions

Function Description
filter-has_var() Checks if a variable of a specified input type exist
filter-id() Returns the filter ID of a specified filter name
filter-input() Gets an external variable (e.g. from form input) and optionally filters it
filter-input_array() Gets external variables (e.g. from form input) and optionally filters them
filter-list() Returns a list of all supported filters
filter-var_array() Gets multiple variables and filter them
filter-var() Filters a variable with a specified filter

PHP 5 Predefined Filter Constants

Constant ID Description
filter-VALIDATE_BOOLEAN 258 Validates a boolean
filter-VALIDATE_EMAIL 274 Validates an e-mail address
filter-VALIDATE_FLOAT 259 Validates a float
filter-VALIDATE_INT 257 Validates an integer
filter-VALIDATE_IP 275 Validates an IP address
filter-VALIDATE_REGEXP 272 Validates a regular expression
filter-VALIDATE_URL 273  Validates a URL
filter-SANITIZE_EMAIL 517 Removes all illegal characters from an e-mail address
filter-SANITIZE_ENCODED 514 Removes/Encodes special characters
filter-SANITIZE_MAGIC_QUOTES 521 Apply addslashes()
filter-SANITIZE_NUMBER_FLOAT 520 Remove all characters, except digits, +- and optionally .,eE
filter-SANITIZE_NUMBER_INT 519 Removes all characters except digits and + -
filter-SANITIZE_SPECIAL_CHARS 515 Removes special characters
filter-SANITIZE_FULL_SPECIAL_CHARS    
filter-SANITIZE_STRING 513 Removes tags/special characters from a string
filter-SANITIZE_STRIPPED 513 Alias of filter-SANITIZE_STRING
filter-SANITIZE_URL 518 Removes all illegal character from s URL
filter-UNSAFE_RAW 516 Do nothing, optionally strip/encode special characters
filter-CALLBACK 1024 Call a user-defined function to filter data