The FILTER_CALLBACK filter calls user-defined functions to filter data.
This filter gives us full control over data filtering.
The specified function must be stored in an associative array named "options". See examples below.
Name: "callback"
ID-number: 1024
Tip: You can create your own function, or use an existing PHP function.
Use user-defined functions:
<?phpfunction convertSpace($string) { return str_replace(" ", "_", $string); }$string = "Peter is a great guy!";echo filter_var($string, FILTER_CALLBACK,array("options"= >"convertSpace"));?>
The output of the code looks like this:
Peter_is_a_great_guy!
Use existing PHP functions:
<?php$string="Peter is a great guy!";echo filter_var($string, FILTER_CALLBACK,array("options"=>"strtoupper"));?>
The output of the code looks like this:
PETER IS A GREAT GUY!