为filter_input_array构建自定义FILTER_VALIDATE_XY

时间:2013-02-19 09:24:35

标签: php validation passwords

我无法找到有关在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);

1 个答案:

答案 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'
                        )
);

通过http://devzone.zend.com/703/php-built-in-input-filtering/