how to use filter_input NO $ _POST

0

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.

    
asked by anonymous 24.03.2017 / 12:42

1 answer

1

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);
    
24.03.2017 / 13:22