How to use filter input array in PHP

This article describe about filter_input_array() Function in PHP.
  • 4349

filter_input_array() Function

This function gets multiple external variable and filters them. Example getting the input.

Without calling filter_input() keep on (over and over)  filter_input_array() function filter the several input variable. It is main importance of this function.

From several sources function can get input.

  • INPUT_ENV
  • INPUT_SERVER
  • INPUT_GET
  • INPUT_POST
  • INPUT_COOKIE
  • INPUT_SESSION (Not yet implemented)
  • INPUT_REQUEST (Not yet implemented)

On success return array of data and FALSE on failure.

Syntax

filter_input_array (input_type, filter_args)

 

Parameter Description
input_type Required. Define the input type.
filter_args Optional. Specifies an array of filter arguments.

Example

<html>
<body>
<?php
$arr = array
(
"name" => "peter griffin",
"age" => "41",
"email" => "[email protected]",
);

$filters = array
(
"name" => array
(
"filter"=>FILTER_CALLBACK,
"flags"=>FILTER_FORCE_ARRAY,
"options"=>"ucwords"
),
"age" => array
(
"filter"=>FILTER_VALIDATE_INT,
"options"=>array
(
"min_range"=>1,
"max_range"=>120
)
),
"email"=> FILTER_VALIDATE_EMAIL,
);

print_r(filter_var_array($arr, $filters));
?>
</body>
</html>

 

Output


pic8.jpg

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

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.