filter¶
The filter extension is a built-in extension that provides an efficient way to filter, validate and sanitize data. Give it a string, and check that is satisfy a specific format.
filter works on incoming data, such as $_GET or $_POST, but also on free variables.
<?php
$data = [
'age' => '123 years',
'name' => 'John Doe',
];
$filters = [
'age' => FILTER_VALIDATE_INT,
'name' => FILTER_SANITIZE_ENCODED,
];
print_r(filter_var_array($data, $filters));
?>
See also PHP Filter and Filter Constant.
Related : Extensions, Validation, Sanitation, Incoming Data, php://filter, Ctype, Email
Related packages : clue/stream-filter, laminas/laminas-filter
Added in PHP 7.0+