是否可以对任何POST输入应用过滤器(比如修剪)并删除_POST


Is it possible to apply a filter (say a trim) and remove the _POST to any POST input?

是否可以构建类似的函数

filterAllPost(ANY-POST-VARIABLE-TOTHIS PAGE, filterFunction);
filterFunction($argument){
// apply filter, eg. trim()
}

例如,如果我提交一份带有$id的表格我自动导入变量,修剪并将变量返回为$id,而不是$_POST['id']

我认为array_map()正是您所需要的:http://php.net/manual/en/function.array-map.php

<?php
function filter($n)
{
    return(trim($n));
}
$post = array_map("filter", $_POST);
print_r($post);
?>

不知道是否可以覆盖$_POST变量…