Latest web development tutorials

PHP filter_input_array () function

PHP Filter Reference Complete PHP Filter Reference

Definition and Usage

filter_input_array () function to get the number of inputs (such as form input) from the outside of the script, and filtered.

This function is useful filter more input variables, without calling filter_input ().

This function can take input from a variety of sources:

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

If successful, an array of places to return filtered data. If it fails, it returns FALSE.

grammar

filter_input_array(input_type, filter_args)

参数 描述
input_type 必需。规定输入类型。参见上面的列表中可能的类型。
filter_args 可选。规定过滤器参数数组。合法的数组键名是变量名,合法的值是过滤器 ID,或者规定过滤器、标志以及选项的数组。

该参数也可以是一个单一的过滤器 ID,如果是这样,输入数组中的所有值由指定过滤器进行过滤。

过滤器 ID 可以是 ID 名称(比如 FILTER_VALIDATE_EMAIL)或 ID 号(比如 274)。



Tips and Notes

Tip: See complete PHP Filter Reference view can be used in conjunction with the function of the filter.


Examples

In this case, we use filter_input_array () function to filter three POST variables. POST variable received is name, age and e-mail address:

<?php
$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_input_array(INPUT_POST, $filters));
?>

Output code is as follows:

Array
(
[name] => Peter
[age] => 41
[email] => [email protected]
)


PHP Filter Reference Complete PHP Filter Reference