Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use a custom filter with PHP filter_var() and filter_input()

Tags:

php

PHP Filters are pretty cool, but what do you do if the filters don't quite match what you want? Can you create a custom filter?

like image 505
fijiaaron Avatar asked Jun 10 '10 17:06

fijiaaron


People also ask

What should the Filter_var () function be used on?

filter_var() is a PHP function used to filters a variable with the help of a specified filter. In PHP programming language we can use filter_var() function to validate and sanitize a data such as email id, IP address etc.

How many types of filters are there in PHP?

Introduction ¶ There are two main types of filtering: validation and sanitization.

What is filtering input in PHP?

The PHP filter_input() function allows you to get an external variable by its name and filter it using one or more built-in filters. The following shows the syntax of the filter_input() function: filter_input ( int $type , string $var_name , int $filter = FILTER_DEFAULT , array|int $options = 0 ) : mixed.


1 Answers

Yes, you can use FILTER_CALLBACK and provide your own filter function (as callback).

like image 168
Felix Kling Avatar answered Oct 03 '22 04:10

Felix Kling