Home >Backend Development >PHP Tutorial >filterconfig PHP filter_var function Filter function
The filter_var() function filters variables through a specified filter.
Returns filtered data if successful, false if failed.
Syntax
filter_var(variable, filter, options)variable: required. Specifies the variables to filter.
filter: optional. Specifies the ID of the filter to use. (See list of FiltersIDs below)
options: Specifies an array containing flags/options. Check the possible flags and options for each filter.
Copy the code The 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='255.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 '
';
echo $email_c.' : ';
echo (filter_var($email_c,FILTER_VALIDATE_EMAIL))?'is valid':'is not valid';
echo '
' ;
echo $ip_a.' :';
echo (filter_var($ip_a,FILTER_VALIDATE_IP))?'is valid':'is not valid';
echo '
';
echo $ip_b.' :';
echo (filter_var($ip_b,FILTER_VALIDATE_IP))?'is valid':'is not valid';
echo '
';
echo $ip_c.' :';
echo (filter_var($ip_c,FILTER_VALIDATE_IP))?'is valid':'is not valid';
?>
The above introduces the filterconfig PHP filter_var function Filter function, including the content of filterconfig. I hope it will be helpful to friends who are interested in PHP tutorials.