PHP Filter_var Function

What is filter_var() in PHP?

Explanation

filter_var() is a function, used to validate a value of a variable. This function returns the filtered data on success or FALSE on failure.

Syntax:


filter_var(variable, filter, options)

Example :


<?php
$val=12344;
if (!filter_var($val, FILTER_VALIDATE_INT))
{
echo "This Value is not a number";
}
else
{
echo "This Value is a number";
}
?>

Result :

This Value is a number

In the above example, the variable value stored in $val is 12344, which is a number. It is determined and validated using filter_var() function.

PHP Topics


Ask Questions

Ask Question