The filter_var() function filters a variable through a specified filter. If successful, the filtered data is returned. If it fails, returns FALSE.
filter_var(variable, filter, options)
parameter | describe |
---|---|
variable | Required. Specifies the variables to filter. |
filter | Optional. Specifies the ID of the filter to use. The default is FILTER_SANITIZE_STRING. See the complete PHP Filter reference manual to view possible filters. The filter ID can be an ID name (such as FILTER_VALIDATE_EMAIL) or an ID number (such as 274). |
options | Optional. Specifies an associative array of flags/options or a single flag/option. Check the possible flags and options for each filter. |
<?phpif(!filter_var("[email protected]", FILTER_VALIDATE_EMAIL)) { echo("E-mail is not valid"); }else { echo("E-mail is valid"); }? >
The output of the code looks like this:
Email is not valid