Difference between revisions of "PHP filters"
(Created page with "Filters can be used to both sanitize and validate data. Filters available are: *int *boolean *float *validate_regexp *validate_url *validate_email *validate_ip *string *stri...") |
|||
Line 1: | Line 1: | ||
− | Filters can be used to both sanitize and validate data. Filters available are: | + | 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: | ||
+ | |||
+ | <syntaxhighlight lang=php> | ||
+ | <?php | ||
+ | $int = 10.5; | ||
+ | |||
+ | if (filter_var($int, FILTER_VALIDATE_INT)) { | ||
+ | echo("Integer is valid"); | ||
+ | } else { | ||
+ | echo("Integer is not valid"); | ||
+ | } | ||
+ | ?> | ||
+ | </syntaxhighlight> | ||
+ | Filters available are: | ||
*int | *int |
Revision as of 14:09, 20 December 2017
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