To filter a variable, use one of the following filter functions:
- filter_var() - Filters a single variable with a specified filter
- filter_var_array() - Filter several variables with the same or different filters
- filter_input - Get one input variable and filter it
- filter_input_array - Get several input variables and filter them with the same or different filters
In the example below, we validate an integer using the filter_var() function:
< ?php |
The code above uses the "FILTER_VALIDATE_INT" filter to filter the variable. Since the integer is valid, the output of the code above will be: "Integer is valid".
If we try with a variable that is not an integer (like "123abc"), the output will be: "Integer is not valid".
For a complete list of functions and filters, visit our PHP Filter Reference.