Home  >  Article  >  Backend Development  >  filter_var() function in PHP

filter_var() function in PHP

PHPz
PHPzforward
2023-09-09 20:41:09914browse

filter_var() function in PHP

The filter_var() function is used to filter variables using the specified filter.

Syntax

filter_var(variable, filter, options)

Parameters

  • variable − The name of the variable.

  • #filter − The name of the filter whose ID is to be obtained.

  • options − Specifies the options to use.

Return value

The filter_var() function returns filtered data when successful, and returns false when failed.

Example

Demonstration

<?php
   $myEmail = "examplee@demo.com";
   if (filter_var($myEmail, FILTER_VALIDATE_EMAIL {
      echo("$myEmail = valid email address");
   } else {
      echo("$myEmail = invalid email address");
   }
?>

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete