Home > Article > Backend Development > filter_var() function in PHP
The filter_var() function is used to filter variables using the specified filter.
filter_var(variable, filter, options)
variable − The name of the variable.
#filter − The name of the filter whose ID is to be obtained.
options − Specifies the options to use.
The filter_var() function returns filtered data when successful, and returns false when failed.
Demonstration
<?php $myEmail = "examplee@demo.com"; if (filter_var($myEmail, FILTER_VALIDATE_EMAIL { echo("$myEmail = valid email address"); } else { echo("$myEmail = invalid email address"); } ?>
The following is the output result.
examplee@demo.com = valid email address
The above is the detailed content of filter_var() function in PHP. For more information, please follow other related articles on the PHP Chinese website!