The filter_var () function filters variables using the specified filter.
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.
Copy codeThe Code is as follows:
<?
@ Header ('content-type: text/html; charset = UTF-8 ;');
$ Email_a = 'jcifox @ gmail.com ';
$ Email_ B = '@ jcifox@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 '<br/> ';
Echo $ email_ B .':';
Echo (filter_var ($ email_ B, FILTER_VALIDATE_EMAIL ))? 'Is valid': 'is not valid ';
Echo '<br/> ';
Echo $ email_c .':';
Echo (filter_var ($ email_c, FILTER_VALIDATE_EMAIL ))? 'Is valid': 'is not valid ';
Echo '<br/> ';
Echo $ ip_a .':';
Echo (filter_var ($ ip_a, FILTER_VALIDATE_IP ))? 'Is valid': 'is not valid ';
Echo '<br/> ';
Echo $ ip_ B .':';
Echo (filter_var ($ ip_ B, FILTER_VALIDATE_IP ))? 'Is valid': 'is not valid ';
Echo '<br/> ';
Echo $ ip_c .':';
Echo (filter_var ($ ip_c, FILTER_VALIDATE_IP ))? 'Is valid': 'is not valid ';
?>
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.