Open In App

PHP | filter_var() Function

The filter_var() function filters a variable with the specified filter. This function is used to both validate and sanitize the data.

Syntax :-



filter_var(var, filtername, options)

Parameters: This function accepts three parameters and are described below:

  1. var : It is the required field. It denotes the variable to filter.
  2. filtername : It is used to specify the ID or name of the filter to use. Default is FILTER_DEFAULT, which results in no filtering. It is optional field.
  3. options : It is used to specify one or more flags/options to use. Check each filter for possible options and flags. It is also optional field.

Return Value: It returns the filtered data on success, or FALSE on failure.



Below are some different applications of filter_var() function:

Reference:
http://php.net/manual/en/function.filter-var.php


Article Tags :