Javascript debugger
Website design
↑
This extension serves to validate and filter data coming from some insecure source, such as user input.
The following filters currently exist; be sure to read the Filter Constants section for information that describes the behavior of each constant:
ID | Name | Options | Flags | Description |
---|---|---|---|---|
FILTER_VALIDATE_INT | "int" | min_range, max_range |
FILTER_FLAG_ALLOW_OCTAL ,
FILTER_FLAG_ALLOW_HEX
| Validates value as integer, optionally from the specified range. |
FILTER_VALIDATE_BOOLEAN | "boolean" |
FILTER_NULL_ON_FAILURE
|
Returns
If | |
FILTER_VALIDATE_FLOAT | "float" | decimal |
FILTER_FLAG_ALLOW_THOUSAND
| Validates value as float. |
FILTER_VALIDATE_REGEXP | "validate_regexp" | regexp | Validates value against regexp, a Perl-compatible regular expression. | |
FILTER_VALIDATE_URL | "validate_url" |
FILTER_FLAG_PATH_REQUIRED ,
FILTER_FLAG_QUERY_REQUIRED
| Validates value as URL, optionally with required components. | |
FILTER_VALIDATE_EMAIL | "validate_email" | Validates value as e-mail. | ||
FILTER_VALIDATE_IP | "validate_ip" |
FILTER_FLAG_IPV4 ,
FILTER_FLAG_IPV6 ,
FILTER_FLAG_NO_PRIV_RANGE ,
FILTER_FLAG_NO_RES_RANGE
| Validates value as IP address, optionally only IPv4 or IPv6 or not from private or reserved ranges. | |
FILTER_SANITIZE_STRING | "string" |
FILTER_FLAG_NO_ENCODE_QUOTES ,
FILTER_FLAG_STRIP_LOW ,
FILTER_FLAG_STRIP_HIGH ,
FILTER_FLAG_ENCODE_LOW ,
FILTER_FLAG_ENCODE_HIGH ,
FILTER_FLAG_ENCODE_AMP
| Strip tags, optionally strip or encode special characters. | |
FILTER_SANITIZE_STRIPPED | "stripped" | Alias of "string" filter. | ||
FILTER_SANITIZE_ENCODED | "encoded" |
FILTER_FLAG_STRIP_LOW ,
FILTER_FLAG_STRIP_HIGH ,
FILTER_FLAG_ENCODE_LOW ,
FILTER_FLAG_ENCODE_HIGH
| URL-encode string, optionally strip or encode special characters. | |
FILTER_SANITIZE_SPECIAL_CHARS | "special_chars" |
FILTER_FLAG_STRIP_LOW ,
FILTER_FLAG_STRIP_HIGH ,
FILTER_FLAG_ENCODE_HIGH
|
HTML-escape '"<>& and characters with
ASCII value less than 32, optionally strip or encode other special
characters.
| |
FILTER_UNSAFE_RAW | "unsafe_raw" |
FILTER_FLAG_STRIP_LOW ,
FILTER_FLAG_STRIP_HIGH ,
FILTER_FLAG_ENCODE_LOW ,
FILTER_FLAG_ENCODE_HIGH ,
FILTER_FLAG_ENCODE_AMP
| Do nothing, optionally strip or encode special characters. | |
FILTER_SANITIZE_EMAIL | "email" |
Remove all characters except letters, digits and
!#$%&'*+-/=?^_`{|}~@.[] .
| ||
FILTER_SANITIZE_URL | "url" |
Remove all characters except letters, digits and
$-_.+!*'(),{}|\\^~[]`<>#%";/?:@&= .
| ||
FILTER_SANITIZE_NUMBER_INT | "number_int" |
Remove all characters except digits and +- .
| ||
FILTER_SANITIZE_NUMBER_FLOAT | "number_float" |
FILTER_FLAG_ALLOW_FRACTION ,
FILTER_FLAG_ALLOW_THOUSAND ,
FILTER_FLAG_ALLOW_SCIENTIFIC
|
Remove all characters except digits, +- and
optionally .,eE .
| |
FILTER_SANITIZE_MAGIC_QUOTES | "magic_quotes" | Apply addslashes(). | ||
FILTER_CALLBACK | "callback" | callback function or method | Call user-defined function to filter data. |
A short installation note: just type
$ pecl install filter
in your console.
The behaviour of these functions is affected by settings in php.ini
.
Name | Default | Changeable | Changelog |
---|---|---|---|
filter.default | "unsafe_raw" | PHP_INI_PERDIR | PHP_INI_ALL in filter <= 0.9.4. Available since PHP 5.2.0. |
filter.default_flags | NULL | PHP_INI_PERDIR | PHP_INI_ALL in filter <= 0.9.4. Available since PHP 5.2.0. |
For further details and definitions of the
PHP_INI_* constants, see the Appendix I, php.ini
directives.
Here's a short explanation of the configuration directives.
Filter all $_GET, $_POST, $_COOKIE and $_REQUEST data by this filter. Original data can be accessed through filter_input().
Accepts the name of the filter you like to use by default. See the existing filter list for the list of the filter names.
Default flags
The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
INPUT_POST
(integer)
INPUT_GET
(integer)
INPUT_COOKIE
(integer)
INPUT_ENV
(integer)
INPUT_SERVER
(integer)
INPUT_SESSION
(integer)
INPUT_REQUEST
(integer)
FILTER_FLAG_NONE
(integer)
FILTER_REQUIRE_SCALAR
(integer)
FILTER_REQUIRE_ARRAY
(integer)
FILTER_FORCE_ARRAY
(integer)
FILTER_NULL_ON_FAILURE
(integer)
FILTER_VALIDATE_INT
(integer)
FILTER_VALIDATE_BOOLEAN
(integer)
FILTER_VALIDATE_FLOAT
(integer)
FILTER_VALIDATE_REGEXP
(integer)
FILTER_VALIDATE_URL
(integer)
FILTER_VALIDATE_EMAIL
(integer)
FILTER_VALIDATE_IP
(integer)
FILTER_DEFAULT
(integer)
FILTER_UNSAFE_RAW
(integer)
FILTER_SANITIZE_STRING
(integer)
FILTER_SANITIZE_STRIPPED
(integer)
FILTER_SANITIZE_ENCODED
(integer)
FILTER_SANITIZE_SPECIAL_CHARS
(integer)
FILTER_SANITIZE_EMAIL
(integer)
FILTER_SANITIZE_URL
(integer)
FILTER_SANITIZE_NUMBER_INT
(integer)
FILTER_SANITIZE_NUMBER_FLOAT
(integer)
FILTER_SANITIZE_MAGIC_QUOTES
(integer)
FILTER_CALLBACK
(integer)
FILTER_FLAG_ALLOW_OCTAL
(integer)
0[0-7]+
) in "int" filter.
FILTER_FLAG_ALLOW_HEX
(integer)
0x[0-9a-fA-F]+
) in "int" filter.
FILTER_FLAG_STRIP_LOW
(integer)
FILTER_FLAG_STRIP_HIGH
(integer)
FILTER_FLAG_ENCODE_LOW
(integer)
FILTER_FLAG_ENCODE_HIGH
(integer)
FILTER_FLAG_ENCODE_AMP
(integer)
&
.
FILTER_FLAG_NO_ENCODE_QUOTES
(integer)
'
and "
.
FILTER_FLAG_EMPTY_STRING_NULL
(integer)
FILTER_FLAG_ALLOW_FRACTION
(integer)
FILTER_FLAG_ALLOW_THOUSAND
(integer)
,
) in "number_float" filter.
FILTER_FLAG_ALLOW_SCIENTIFIC
(integer)
e
, E
) in
"number_float" filter.
FILTER_FLAG_SCHEME_REQUIRED
(integer)
FILTER_FLAG_HOST_REQUIRED
(integer)
FILTER_FLAG_PATH_REQUIRED
(integer)
FILTER_FLAG_QUERY_REQUIRED
(integer)
FILTER_FLAG_IPV4
(integer)
FILTER_FLAG_IPV6
(integer)
FILTER_FLAG_NO_RES_RANGE
(integer)
FILTER_FLAG_NO_PRIV_RANGE
(integer)
Table of Contents