PHP filter_input () function

Source: Internet
Author: User
Tags 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.
Example

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:

 
Email is valid

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.