PHP FilterFunctions
PHP Filter Introduction
PHP filters are used to validate and filter data from non-secure sources (such as user input).
Installation
The Filter functions are part of the PHP core. No installation is required to use these functions.
PHP Filter Functions
PHP: Indicates the earliest PHP version that supports this function.
| Function | Description | PHP |
|---|---|---|
| filter_has_var() | Checks whether a variable of the specified input type exists. | 5 |
| filter_id() | Returns the ID number of the specified filter. | 5 |
| filter_input() | Gets input from outside the script and filters it. | 5 |
| filter_input_array() | Gets multiple inputs from outside the script and filters them. | 5 |
| filter_list() | Returns an array containing all supported filters. | 5 |
| filter_var_array() | Gets multiple variables and filters them. | 5 |
| filter_var() | Gets a single variable and filters it. | 5 |
PHP Filters
| ID Name | Description |
|---|---|
| FILTER_CALLBACK | Calls a user-defined function to filter data. |
| FILTER_SANITIZE_STRING | Strips tags, removes or encodes special characters. |
| FILTER_SANITIZE_STRIPPED | Alias of the "string" filter. |
| FILTER_SANITIZE_ENCODED | URL-encode the string, removes or encodes special characters. |
| FILTER_SANITIZE_SPECIAL_CHARS | HTML-escapes characters '"<>& and characters with ASCII values less than 32. |
| FILTER_SANITIZE_EMAIL | Removes all characters except letters, digits, and !#$%&'*+-/=?^_`{|}~@.[] |
| FILTER_SANITIZE_URL | Removes all characters except letters, digits, and $-_.+!*'(),{}|\^~[]`<>#%";/?:@&= |
| FILTER_SANITIZE_NUMBER_INT | Removes all characters except digits and +- |
| FILTER_SANITIZE_NUMBER_FLOAT | Removes all characters except digits, +-, and .,eE |
| FILTER_SANITIZE_MAGIC_QUOTES | Applies addslashes(). |
| FILTER_UNSAFE_RAW | Does no filtering, removes or encodes special characters. |
| FILTER_VALIDATE_INT | Validates the value as an integer. |
| FILTER_VALIDATE_BOOLEAN | Validates the value as a boolean option. Returns TRUE for "1", "true", "on", and "yes". Returns FALSE for "0", "false", "off", "no", and "". Otherwise returns NULL. |
| FILTER_VALIDATE_FLOAT | Validates the value as a float. |
| FILTER_VALIDATE_REGEXP | Validates the value against regexp (a Perl-compatible regular expression). |
| FILTER_VALIDATE_URL | Validates the value as a URL. |
| FILTER_VALIDATE_EMAIL | Validates the value as an e-mail address. |
| FILTER_VALIDATE_IP | Validates the value as an IP address, only IPv4 or IPv6, or not from private or reserved ranges. |