How to use FILTER CALLBACK in PHP
This article describe about FILTER_CALLBACK Filter in PHP.
FILTER_CALLBACK Filter
For call a user defined function to filter the value FILTER_CALLBACK Filter used. And this filter keep the full control over the data filter.
The defined functions must be in an associative array with the name.
- Name: "callback"
- ID-number: 1024
Note: Here you can create your own function ( user define ) or used an existing PHP function.
Example 1
User define function.
<html>
<body>
<?php
function convertSpace($string)
{
return str_replace(" ", "_", $string);
}
$string = "sohan is a funny guy!";
echo filter_var($string, FILTER_CALLBACK,
array("options"=>"convertSpace"));
?>
</body>
</html> |
Output

Example 2
Existing PHP function.
<html>
<body>
<?php
$string="sohan is a funny guy!";
echo filter_var($string, FILTER_CALLBACK,
array("options"=>"strtoupper"));
?>
</body>
</html> |
Output

You may also want to read these related articles Click here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here