diff --git a/reference/filter/constants.xml b/reference/filter/constants.xml index a856d6f2c367..6183c804c9a3 100644 --- a/reference/filter/constants.xml +++ b/reference/filter/constants.xml @@ -1039,11 +1039,75 @@ (int) - - ID of "callback" filter. + This filter delegates the filtering to a user defined function. + The callable is passed via the + options parameter as the value associated to + the 'options' key. + + The callback should have the following signature: + + mixedcallback + stringvalue + + + + value + + + The value that is being filtered. + + + + + + + + The value returned by the callback will be the value returned by + the invoked filter function. + + + + + Example of using <constant>FILTER_CALLBACK</constant> to validate + a login name + + += 5 && ctype_alnum($value)) { + return $value; + } + return null; +} + +$login = "val1dL0gin"; +$filtered_login = filter_var($login, FILTER_CALLBACK, ['options' => 'validate_login']); +var_dump($filtered_login); + +$login = "f&ke login"; +$filtered_login = filter_var($login, FILTER_CALLBACK, ['options' => 'validate_login']); +var_dump($filtered_login); +?> +]]> + + &example.outputs; + + + + + + + This filter cannot be used with any other filter flags, e.g. + FILTER_NULL_ON_FAILURE. + + diff --git a/reference/filter/filters.xml b/reference/filter/filters.xml index f0324ba4ef88..8b91702455d5 100644 --- a/reference/filter/filters.xml +++ b/reference/filter/filters.xml @@ -129,37 +129,6 @@ - -
- Other filters - - - List of miscellaneous filters - - - - ID - Name - Options - Flags - Description - - - - - FILTER_CALLBACK - "callback" - callable function or method - All flags are ignored - Call user-defined function to filter data. - - - -
-
-
- -
Filter flags