filter_varWe can check a variable by using a particular type of filter by using filter_var() function. This function takes the variable and the ID or name of the filter as input and checks the variable. It returns True of False based on the checking output. Here is the syntax.
We will try with an example with book_id as variable
You can get list of filter ID here
IN the above code we have not user filter id and in that place we have used filter Name. Now let us try one email validation by using email filter
We can replace the email filter name with email filter ID ( 274 ) , just change the above line with this
This article is written by plus2net.com team.
filter_list:PHP list of filters available and how to display
filter_has_var: checking the existance of variable in PHP
filter_var: Validating variable using filter id
FILTER_VALIDATE_FLOAT: Validating Float data FILTER_VALIDATE_INT: Validating Integer with Maximum and Minimum range
FILTER_VALIDATE_REGEXP: Validating REgular Expression
FILTER_VALIDATE_EMAIL: Validating Email
FILTER_VALIDATE_URL: Validating URL with query string and path
FILTER_VALIDATE_IP: Validating IPV4 and IPV6 address
FILTER_VALIDATE_BOOLEAN: Validating boolean variable
FILTER_SANITIZE_STRING: Sanitize string FILTER_SANITIZE_URL: Sanitize url