PHP Filter, how to filter input array PHP Filter, how to filter input array php php

PHP Filter, how to filter input array


I don't think that you can access the single value (easily, as you want), however you could just filter the page array and get the value that you want.

$page = filter_input(INPUT_POST, 'page', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);if (array_key_exists('name', $page)) {    $name = $page['name'];}

Or, if you're OK with losing the ability to work with the raw input then you could just use:

if (isset($_POST['page']['name'])) {    $name = filter_var($_POST['page']['name'], FILTER_SANITIZE_STRING);}

Both, however, are pretty ugly.


How about

$_POST['page'] = filter_var_array($_POST['page'], FILTER_SANITIZE_STRING);