scanning == regexps
As with other answers this one is again based on mastering regular expressions, which is essentially THE basic character scanning (and parsing) technique all those validators are built upon. The idea about validators/filters is to define/guess/cover as many reasonable classes of strings (regexps) as possible. (Plus there is an optimization speed up for trivial classes like [0-9]* or [a-z]* - no need to go via standard perl-compatible)
filter_var_array and callbacks
As a quick remark: indeed, things like FILTER_VALIDATE_REGEXP did not work for me either...
filter_var_array & co. is relatively new practice, but if you must then fallback to whatever custom FILTER_CALLBACK works in the following form:
<?php
error_reporting(E_ALL | E_STRICT);
function handle($value) {
return preg_replace('/[^a-z]/', '', $value);
}
$data = array(
'testfield' => array('22', 'foo', 'bar', '42'),
);
$args = array(
'testfield' => array('filter' => FILTER_CALLBACK,
'options' => 'handle'
),
);
$result = filter_var_array($data, $args);
var_dump($result);
and produces
array(1) {
["testfield"]=>
array(4) {
[0]=>
string(0) ""
[1]=>
string(3) "foo"
[2]=>
string(3) "bar"
[3]=>
string(0) ""
}
}