Sanitizing and validating user input is one of the most common tasks in a web application. To make this task easier PHP provides native filter extension that you can use to sanitize or validate data such as e-mail addresses, URLs, IP addresses, etc.
This function takes three parameters out of which the last two are optional. The first parameter is the value to be filtered, the second parameter is the ID of the filter to apply, and the third parameter is the array of options related to filter. Let's see how it works.
Sanitize a String
The following example will validate whether the value is a valid integer or not.
The following example will validate whether the value is a valid IP address or not.
The following example will show you how to sanitize and validate an e-mail address.
The following example will show you how to sanitize and validate a url.
The following example will validate whether the supplied value is an integer or not, as well as whether it lies within the range of 0 to 100 or not.