The PHP filter is used to verify and filter data from unsafe sources (such as user input). The filter_var () function uses the specified filter to filter variables.
If the operation succeeds, filtered data is returned. if the operation fails, false is returned.
Syntax
Filter_var (variable, filter, options) variable: required. Specifies the variable to be filtered.
Filter: Optional. Specifies the ID of the filter to be used. (See the following FiltersID list)
Options: specifies the array containing the flag/option. Check the possible flags and options of each filter.
The code is as follows:
@ Header ('content-type: text/html; charset = utf-8 ;');
$ Email_a = 'jcifox @ gmail.com ';
$ Email_ B = 'Gmail. com ';
$ Email_c = 'jcifoxgmail. com ';
$ Ip_a = '0. 0.0.0 ';
$ Ip_ B = '2017. 255.255.255 ';
$ Ip_c = '0. 0.0.265 ';
Echo $ email_a .':';
Echo (filter_var ($ email_a, FILTER_VALIDATE_EMAIL ))? 'Is valid': 'is not valid ';
Echo'
';
Echo $ email_ B .':';
Echo (filter_var ($ email_ B, FILTER_VALIDATE_EMAIL ))? 'Is valid': 'is not valid ';
Echo'
FiltersID name: Description
FILTER_CALLBACK: Call a user-defined function to filter data.
FILTER_SANITIZE_STRING: remove tags, or encode special characters.
FILTER_SANITIZE_STRIPPED: "string" filter alias.
FILTER_SANITIZE_ENCODED: URL-encode string. special characters are removed or encoded.
FILTER_SANITIZE_SPECIAL_CHARS: HTML escape character '"<> & and characters with ASCII values less than 32.
FILTER_SANITIZE_EMAIL: delete all characters except letters, numbers, and! # $ % & '* +-/=? ^ _ '{| }~ @. []
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: application addslashes ().
FILTER_UNSAFE_RAW: removes or encodes special characters without any filtering.
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: verifies the value with a floating point number.
FILTER_VALIDATE_REGEXP: verifies the value based on regexp, a Perl-compatible regular expression.
FILTER_VALIDATE_URL: use the value as the URL for verification.
FILTER_VALIDATE_EMAIL: use the value as email for verification.
FILTER_VALIDATE_IP: verify the value as an IP address.
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.