PHP filter_input_array() 함수
예시
filter_input_array() 함수를 사용하여 세 가지 POST 변수를 필터링합니다. 수신된 POST 변수는 이름, 나이 및 이메일입니다.
<?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));
?>
위 코드의 출력은 다음과 같습니다.
정의 및 사용
filter_input_array() 함수는 외부 변수(예: 양식 입력에서)를 가져와 선택적으로 필터링합니다.
이 함수는 filter_input()을 여러 번 호출하는 대신 많은 값을 검색/필터링하는 데 유용합니다.
통사론
filter_input_array(type, definition, add_empty)
매개변수 값
Parameter | Description |
---|---|
type | Required. The input type to check for. Can be one of the following:
|
definition | Optional. Specifies an array of filter arguments. A valid array key is a variable name, and a valid value is a filter name or ID, or an array specifying the filter, flags and options. This parameter can also be a single filter name/ID; then all values in the input array are filtered by the specified filter |
add_empty | Optional. A Boolean value. TRUE adds missing keys as NULL to the return value. Default value is TRUE |
기술적 세부 사항
반환 값: | 성공 시 변수 값이 있는 배열, 실패 시 FALSE |
---|---|
PHP 버전: | 5.2+ |
PHP 변경 로그: | PHP 5.4 - add_empty 매개변수가 추가되었습니다 . |
❮ 전체 PHP 필터 참조