PHP Filter function validation, filtering user input data _php skills

Source: Internet
Author: User
Introduction to PHP Filter

The PHP filter is used to validate and filter data from unsecured sources, such as user input.
Copy Code code as follows:

Remove HTML tags, or remove coded special characters
Var_dump (Filter_var ("
url_encoded encoding, removing or encoding special characters
Var_dump (Filter_var ("http://Chinese ah", filter_sanitize_encoded));

HTML escape character "" <>& and ASCII value less than 32 characters.
Var_dump (Filter_var ("<a&b#\" > ", Filter_sanitize_special_chars)");

Remove all characters except letters, numbers, and!#$%& ' *+-/=?^_ ' {|} ~@. []
Var_dump (Filter_var ("as$&><", Filter_sanitize_email));

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

Remove all characters except numbers and +-
Var_dump (Filter_var ("123abc++", Filter_sanitize_number_int));

Remove all characters except numbers, +-, and., EE.
Var_dump (Filter_var ("mm.,pp", filter_sanitize_number_float));

Application Addslashes
Var_dump (Filter_var ("aa//", filter_sanitize_magic_quotes));

Validates values with integers in the specified range
Var_dump (Filter_var (20,filter_validate_int,array ("Options" =>array ("Min_range" =>10, "Max_range" =>51))) ;

Returns True if "1", "true", "on", and "Yes", and False if "0", "false", "off", "No", and "". Otherwise NULL is returned.
Var_dump (Filter_var (1,filter_validate_boolean));

Validates values with floating-point numbers.
Var_dump (Filter_var (222,filter_validate_float));

Verifying URLs
Var_dump (Filter_var ("http://www.baidu.com", Filter_validate_url));

Verify Email
Var_dump (Filter_var ("abcd@123.com", Filter_validate_email));

Verifying IP addresses
Var_dump (Filter_var ("1.1.1.266", filter_validate_ip));

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.