Display the drop-down list

filter_var()

« filter_list | filter_var_array »
<?php
// custom callback functions
function cube($n)    { return($n $n $n); }
function 
foo($value) {
    if (
strpos($value", ") === false// expected format: Surname, GivenNames
        
return false;

    list(
$surname$givennames) = explode(", "$value2);
    
$empty = (empty($surname) || empty($givennames));
    
$notstrings = (!is_string($surname) || !is_string($givennames));

    if (
$empty || $notstrings) {
        return 
false;
    } else {
        return 
$value;
    }
}

// adds custom callback functions, closures and methods
require "pbx_callbacks.php";
$object = new pbx_callbacks();

$mixed filter_var (
    
// mixed $variable
    
?// [int $filter = FILTER_DEFAULT]
    
  // [mixed $options]
);
?>
Result
$mixed = '127.0.0.1'
Examples
#1 filter_var  ("0755",
 
FILTER_VALIDATE_INT,
 [
"options" => ["default" => 3"min_range" => 0], "flags" => FILTER_FLAG_ALLOW_OCTAL])
#2 filter_var  ("oops",
 
FILTER_VALIDATE_BOOLEAN,
 
FILTER_NULL_ON_FAILURE)
#3 filter_var  ("oops",
 
FILTER_VALIDATE_BOOLEAN,
 [
"flags" => FILTER_NULL_ON_FAILURE])
#4 filter_var  ("Doe, Jane Sue",
 
FILTER_CALLBACK,
 [
"options" => "foo"])
#5 filter_var  ("bob@example.com",
 
FILTER_VALIDATE_EMAIL)
#6 filter_var  ("http://example.com",
 
FILTER_VALIDATE_URL,
 
FILTER_FLAG_PATH_REQUIRED)
#7 filter_var  ("127.0.0.1",
 
FILTER_VALIDATE_IP)
#8 filter_var  ("1",
 
FILTER_VALIDATE_INT,
 [
"options" => ["default" => 3"min_range" => 0]])
#9 filter_var  ("-1",
 
FILTER_VALIDATE_INT,
 [
"options" => ["default" => 3"min_range" => 0]])
#10 filter_var  ("4",
 
FILTER_VALIDATE_INT,
 [
"options" => ["default" => 3"min_range" => 0]])
#11 filter_var  ("(bob@example.com)",
 
FILTER_SANITIZE_EMAIL)
#12 filter_var  ("Doe Jane Sue",
 
FILTER_CALLBACK,
 [
"options" => "foo"])
#13 filter_var  ("bogus",
 
FILTER_VALIDATE_EMAIL)
#14 filter_var  ("42.42",
 
FILTER_VALIDATE_IP)
#15 filter_var  (3,
 
FILTER_CALLBACK,
 [
"options" => "cube"])
#16 filter_var  (3,
 
FILTER_CALLBACK,
 [
"options" => $cube])
#17 filter_var  (3,
 
FILTER_CALLBACK,
 [
"options" => "pbx_callbacks::cube"])
#18 filter_var  (3,
 
FILTER_CALLBACK,
 [
"options" => [=> $object=> "cube"]])
See also
explode, filter_input, filter_input_array, filter_var_array, is_string, pbx_callbacks, strpos