Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

PHP Filter function


May 11, 2021 PHP


Table of contents


PHP Filter function

For data in PHP, you need to verify that it is secure, and the Filter function helps with this.


Introduction to PHP Filter

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


Installation

The Filter function is part of the PHP core. These functions can be used without installation.


PHP Filter function

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

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


PHP Filters

ID name describe
FILTER_CALLBACK Call the user-defined function to filter data.
FILTER_SANITIZE_STRING Remove the label, remove or encode special characters.
FILTER_SANITIZE_STRIPPED The alias of the "String" filter.
FILTER_SANITIZE_ENCODED URL-ENCODE string, remove or encode special characters.
FILTER_SANITIZE_SPECIAL_CHARS HTML escape character '"<> & and ASCII values are less than 32 characters.
FILTER_SANITIZE_EMAIL Delete all characters, except for letters, numbers, and! # $% & '* + - / =? ^ _ `{|} ~ @.
FILTER_SANITIZE_URL Delete all characters, except for letters, numbers, and $ -_. +! * '(), {} | \ ^ ~ [] `<> #%"; /?: @ & =
FILTER_SANITIZE_NUMBER_INT Delete all characters, in addition to numbers and + -
FILTER_SANITIZE_NUMBER_FLOAT Delete all characters, in addition to numbers, + -, and., EE
FILTER_SANITIZE_MAGIC_QUOTES Apply addslashes ().
FILTER_UNSAFE_RAW Do not perform any filtration, removal, or encoding special characters.
FILTER_VALIDATE_INT Valide the value as an integer.
FILTER_VALIDATE_BOOLEAN Take the value as the Boolean option to verify.Returns true if "1", "True", "ON" and "Yes".If it is "0", "False", "Off", "NO", ", then returns false.Otherwise returns NULL.
FILTER_VALIDATE_FLOAT Value the value as the floating point number.
FILTER_VALIDATE_REGEXP Valid values according to Regexp (a regular expression that is compatible with Perl).
FILTER_VALIDATE_URL Take the value as the URL to verify.
FILTER_VALIDATE_EMAIL Take the value as an E-Mail address to verify.
FILTER_VALIDATE_IP Turn the value as an IP address, only IPv4 or IPv6 or is not from private or reserved ranges.

The security of your data is important, so take a closer look at this section!