PHP Filter function validation, filtering user input data _php tutorial

Source: Internet
Author: User
Introduction to PHP Filter

PHP filters are used to validate and filter data from non-secure sources, such as user input.
Copy CodeThe code is as follows:
Remove HTML tags, or remove encoded special characters
Var_dump (Filter_var ("Chinese abc@# BBB ", filter_sanitize_string));

url_encoded encoding, removing or encoding special characters
Var_dump (Filter_var ("http://Chinese AH", filter_sanitize_encoded));

The HTML escape character "" <>& and the ASCII value less than 32 characters.
Var_dump (Filter_var ("", 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 +-out
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 a value with an integer 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 returns False if it is "0", "false", "off", "No", and "". Otherwise, NULL is returned.
Var_dump (Filter_var (1,filter_validate_boolean));

Validates the value with a floating-point number.
Var_dump (Filter_var (222,filter_validate_float));

Verify URL
Var_dump (Filter_var ("http://www.baidu.com", Filter_validate_url));

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

Verify IP Address
Var_dump (Filter_var ("1.1.1.266", filter_validate_ip));

http://www.bkjia.com/PHPjc/695099.html www.bkjia.com true http://www.bkjia.com/PHPjc/695099.html techarticle PHP Filter Introduction PHP filters are used to validate and filter data from non-secure sources, such as user input. Copy the code code as follows://Remove HTML tag, or remove encoding special ...

  • 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.