Filter_input () function

Source: Internet
Author: User
Tags encode string valid email address
Definition and usage

The filter_input () function obtains and filters the input from outside the script.

This function is used to verify variables from unsafe sources, such as user input.

This function can obtain input from various sources:

  • Input_get
  • Input_post
  • Input_cookie
  • Input_env
  • Input_server
  • Input_session (not yet implemented)
  • Input_request (not yet implemented)

If the operation succeeds, the filtered data is returned. If the operation fails, false is returned.VariableIf the parameter is not set, null is returned.

Syntax
filter_input(input_type, variable, filter, options)
Parameters Description
Input_type Required. Specifies the input type. See the possible types in the list above.
Variable Specifies the variable to be filtered.
Filter

Optional. Specifies the ID of the filter to be used. The default value is filter_sanitize_string.

See the complete PHP filter function reference manual to obtain possible filters.

The filter ID can be an ID name (such as filter_validate_email) or an ID (such as 274 ).

Options Specifies an array containing flag/option. Check the possible flags and options of each filter.

 

 

 

 

 

 

In this example, we use the filter_input () function to filter a post variable. The accepted post variable is a valid email address.

<?phpif (!filter_input(INPUT_POST, ‘email‘, FILTER_VALIDATE_EMAIL)) { echo "E-Mail is not valid"; }else { echo "E-Mail is valid"; }?>

The output is similar:

E-Mail is valid

Filter Function

It is used to verify and filter data from non-security sources (such as user input.

The filter function is a core component of PHP. These functions can be used without installation.

PHP: indicates the earliest PHP version that supports this function.

Function Description PHP
Filter_has_var () Check whether a variable of the specified input type exists. 5
Filter_id () Returns the ID of the specified filter. 5
Filter_input () Obtain and filter the input from outside the script. 5
Filter_input_array () Obtain multiple inputs from outside the script and filter them out. 5
Filter_list () Returns an array containing all the supported filters. 5
Filter_var_array () Obtain and filter multiple variables. 5
Filter_var () Obtain and filter a variable. 5










ID Description
Filter_callback You can call a user-defined function to filter data.
Filter_sanitize_string Remove tags, remove or encode special characters.
Filter_sanitize_stripped The alias of the "string" filter.
Filter_sanitize_encoded URL-encode string to remove or encode special characters.
Filter_sanitize_special_chars HTML Escape Character '"<> & characters with ASCII values smaller than 32.
Filter_sanitize_email Delete all characters except letters, numbers, and! # $ % & '* +-/=? ^ _ '{|} [Email protected] []
Filter_sanitize_url Delete all characters except letters, numbers, and $-_. +! * '(), {}|\\^ ~ [] '<> # % ";/? : @ & =
Filter_sanitize_number_int Delete all characters except numbers and +-
Filter_sanitize_number_float Delete all characters except numbers, +-, and., ee.
Filter_sanitize_magic_quotes Use the addslashes () (addslashes () function to add backslashes for escape ).
Filter_unsafe_raw Do not filter, remove, or encode special characters.
Filter_validate_int The value is verified by an integer in the specified range.
Filter_validate_boolean If it is "1", "true", "on", and "yes", true is returned. If it is "0", "false", "off ", "No" and "", false is returned. Otherwise, null is returned.
Filter_validate_float Verify the value with a floating point number.
Filter_validate_regexp Verify the value based on Regexp and Perl-Compatible Regular Expressions.
Filter_validate_url Use the value as the URL for verification.
Filter_validate_email Use the value as email for verification.
Filter_validate_ip Use the value as the IP address for verification.













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.