PHP filters
Filters can be used to both sanitize and validate data.
Validating Integer
This code will check if the value is an integer, 10.5 obviously isn't:
<?php
$int = 10.5;
if (filter_var($int, FILTER_VALIDATE_INT)) {
echo("Integer is valid");
} else {
echo("Integer is not valid");
}
?>
Filters available are:
- int
- boolean
- float
- validate_regexp
- validate_url
- validate_email
- validate_ip
- string
- stripped
- encoded
- special_chars
- full_special_chars
- unsafe_raw
- url
- number_int
- number_float
- magic_quotes
- callback