PHP FILTER_CALLBACK Filter
Definition and Usage
FILTER_CALLBACK filter uses a user-defined function to filter values.
This filter gives us complete control over data filtering.
The specified function must be stored in an associative array named "options". See the example below.
- Name: "callback"
- ID-number: 1024
Hints and Comments
Hint:ທ່ານສາມາດສ້າງຫົວຂໍ້ວັດຖຸຂອງທ່ານເອງຫຼືນຳໃຊ້ຫົວຂໍ້ວັດຖຸ PHP ທີ່ມີຢູ່.
Example
Example 1
<?php
function convertSpace($string)
{
return str_replace(" ", "_", $string);
}
$string = "Peter is a great guy!";
echo filter_var($string, FILTER_CALLBACK
,
array("options"=>"convertSpace"));
?>
Output:
Peter_is_a_great_guy!
Example 2
<?php
$string="Peter is a great guy!";
echo filter_var($string, FILTER_CALLBACK
,
array("options"=>"strtoupper"));
?>
Output:
PETER IS A GREAT GUY!