Validate value as integer in PHP
Description
The following code shows how to validate value as integer.
Example
/* w w w. j a v a2 s . c om*/
<?php
$var=300;
$int_options = array("options"=>
array("min_range"=>0, "max_range"=>256));
var_dump(filter_var($var, FILTER_VALIDATE_INT, $int_options));
/*
Possible options and flags:
min_range - specifies the minimum integer value
max_range - specifies the maximum integer value
FILTER_FLAG_ALLOW_OCTAL - allows octal number values
FILTER_FLAG_ALLOW_HEX - allows hexadecimal number values
*/
?>
The code above generates the following result.