I use filter_input
like this:
filter_input(INPUT_POST, 'nome_input', FILTER_SANITIZE_SPECIAL_CHARS);
I would like to know how to use it in $_POST
for all input, without entering the name.
I use filter_input
like this:
filter_input(INPUT_POST, 'nome_input', FILTER_SANITIZE_SPECIAL_CHARS);
I would like to know how to use it in $_POST
for all input, without entering the name.
Just get all field names with array_keys
and iterate over the same:
foreach(array_keys($_POST) as $var)
{
$filtered[$var] = filter_input(INPUT_POST, $var, FILTER_SANITIZE_SPECIAL_CHARS);
}
In this way, $filtered
will have all values of $_POST
after passing through the filter.
You can alternatively use the array_map
function:
$filtered = array_map(function ($var) {
return filter_input(INPUT_POST, $var, FILTER_SANITIZE_SPECIAL_CHARS);
}, $_POST);