我无法找到有关在filter_input_array中构建自定义验证函数的信息。
是否有可能对我自己的某个功能进行验证?
类似
function FILTER_CUSTOM_FUNCTION($input) { // do something }
$filter = array(
'id' => FILTER_VALIDATE_INT,
'action' => FILTER_SANITIZE_STRING,
'custom_var' => FILTER_CUSTOM_FUNCTION
);
$myArray = filter_input_array(INPUT_GET, $filter);
答案 0 :(得分:0)
解决方案是关键字“FILTER_CALLBACK”:
function check_languages($var) {
static $called = 0;
$called++;
echo "called: $called: $var<br />";
$var = filter_var($var, FILTER_SANITIZE_STRIPPED);
$l = new language($var);
return $l;
}
$filter = array(
'favourites' => array(
'filter' => FILTER_CALLBACK,
'options' => 'check_languages'
)
);