Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP filter_var() Function

PHP filter_var() Function


PHP Filter Reference Manual Complete PHP Filter Reference Manual


Definition and Usage

The filter_var() function filters a variable with a specified filter.

Returns the filtered data on success, or FALSE on failure.

Syntax

filter_var(variable, filter, options)

Parameters Description
variable Required. Specifies the variable to filter.
filter Optional. Specifies the ID of the filter to use. Default is FILTER_SANITIZE_STRING. See Complete PHP Filter Reference Manualfor possible filters.

A 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.

Example

The output of the code is shown below:

E-mail is not valid


PHP Filter Reference Manual Complete PHP Filter Reference Manual