PHP Filter_var () function using the filter function

Source: Internet
Author: User
Tags encode string
The filter function in PHP is a general term for a series of functions, including the Filter_var function in the Filter series function. The filter series functions are part of the PHP core. These functions can be used without installation.

He is primarily used to authenticate and filter data from non-secure sources, such as user input. The Filter_var () function in this case is to filter the variables by the specified filter.

Filter_has_var () checks to see if a variable of the specified input type exists.

FILTER_ID () returns the ID number of the specified filter.

Filter_input () gets input from outside the script and filters it.

Filter_input_array () gets multiple inputs from outside the script and filters them.

Filter_list () returns an array that contains all the supported filters.

Filter_var_array () Gets the multiple variables and filters them.

Filter_var () Gets a variable and filters it.

The following is a look at the definition and usage of the Filter_var function. The Filter_var () function is to filter variables by the specified filter. If successful, returns the filtered data, or false if it fails. Syntax Filter_var (variable, filter, options) parameter description variable required. Specifies the variables to filter.

Filter is optional. Specifies the ID of the filter to be used.
The options rule contains an array of flags/options. Check the possible flags and options for each filter.

As for what filter to use, refer to the complete PHP filter reference manual to see the filters that can be used with this function: http://cn2.php.net/manual/zh/filter.filters.validate.php Chinese is explained as follows:

Filtersid Name and description

Filter_callback: Invokes a user-defined function to filter the data.

Filter_sanitize_string: Remove tags, remove or encode special characters.

Filter_sanitize_stripped: Alias of the "string" filter.

Filter_sanitize_encoded:url-encode string that removes or encodes special characters.

filter_sanitize_special_chars:html escape character ' "<>& and ASCII values less than 32 characters.

Filter_sanitize_email: Remove all characters except letters, numbers, and!#$%& ' *+-/=?^_ ' {|} ~@. []

Filter_sanitize_url: Delete all characters except letters, numbers, and $-_.+!* ' (), {}|\\^~[] ' <>#% ';/?:@&=

Filter_sanitize_number_int: Remove all characters except numbers and +-

Filter_sanitize_number_float: Delete all characters except numbers, +-and., EE.

Filter_sanitize_magic_quotes: Apply Addslashes ().

Filter_unsafe_raw: Do not filter, remove or encode special characters.

Filter_validate_int: Validates the value with an integer in the specified range.

Filter_validate_boolean: Returns True if "1", "true", "on", and "yes", and returns False if it is "0", "false", "off", "No", and "". Otherwise, NULL is returned. Filter_validate_float: Validates the value with a floating-point number.

FILTER_VALIDATE_REGEXP: Validates values based on REGEXP, a Perl-compatible regular expression.

Filter_validate_url: Validates the value as a URL.

Filter_validate_email: Verify the value as an e-mail.

FILTER_VALIDATE_IP: Validates the value as an IP address.

Here is an example of a filter that uses authentication email:

Use PHP Filter_var functions to verify the correctness of e-mail addresses
if (!filter_var ("someone@example....com", Filter_validate_email)) {
Echo ("incorrect email");

Echo ("correct email");

}

The above results will be output:

Incorrect e-mail

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.