Sanitizes to leave only alphanumeric characters.
$filter->sanitize('field')->to('alnum');
Sanitizes to leave only alphabetic characters.
$filter->sanitize('field')->to('alpha');
Sanitizes so that values lower than the range are forced up to the minimum, and values higher than the range are forced down to the maximum.
$filter->sanitize('field')->to('between', $min, $max);
Sanitizes to a strict PHP boolean value. Pseudo-true values include the strings '1', 'y', 'yes', and 'true'; pseudo-false values include the strings '0', 'n', 'no', and 'false'.
// sanitize to `true` and `false`
$filter->sanitize('field')->to('bool');
You can sanitize to alternative true and false values in place of PHP true
and false
.
// sanitize to alternative true and false values
$filter->sanitize('field')->to('bool', $value_if_true, $value_if_false);
Sanitizes the value using a callable/callback. The callback should take two arguments, $subject
and $field
, to indicate the subject and the field within that subject. It should return true
to pass, or false
to fail.
$filter->sanitize('field')->to('callback', function ($subject, $field) {
// always force the field to 'foo'
$subject->$field = 'foo';
return true;
});
N.b.: Always use object notation (
$subject->$field
) and not array notation ($subject[$field]
) in the callable, as the Filter converts arrays to objects on the fly.
Sanitizes the value to a specified date/time format, default 'Y-m-d H:i:s'
.
$filter->sanitize('field')->to('dateTime', $format);
Sanitizes to the value of another field in the subject.
$filter->sanitize('field')->to('field', 'other_field_name');
Sanitizes the value to transform it into a float; for weird strings, this may not be what you expect.
$filter->sanitize('field')->to('float');
Sanitizes the value to transform it into an integer; for weird strings, this may not be what you expect.
$filter->sanitize('field')->to('int');
Sanitizes the value to an ISBN (International Standard Book Number).
$filter->sanitize('field')->to('isbn');
Sanitizes the value to all lowercase characters.
$filter->sanitize('field')->to('lowercase');
Sanitizes the value to begin with a lowercase character.
$filter->sanitize('field')->to('lowercaseFirst');
Sanitizes so that values higher than the maximum are forced down to the maximum.
$filter->sanitize('field')->to('max', $max);
Sanitizes so that values lower than the minimum are forced up to the minimum.
$filter->sanitize('field')->to('min', $min);
Sanitizes the value to force it to the current datetime, default format 'Y-m-d H:i:s'.
$filter->sanitize('field')->to('now', $format);
Removes the field from the subject with unset()
.
$filter->sanitize('field')->to('remove');
Sanitizes the value using preg_replace()
.
$filter->sanitize('field')->to('regex', $expr, $replace);
Sanitizes the value by casting to a string and optionally using str_replace()
to find and replace within the string.
$filter->sanitize('field')->to('string', $find, $replace);
Sanitizes the value to cut off longer values at the right, and str_pad()
shorter ones.
$filter->sanitize('field')->to('strlen', $len[, $pad_string[, $pad_type]]);
Sanitizes the value to truncate values longer than the maximum, and str_pad()
shorter ones.
$filter->sanitize('field')->to('strlenBetween', $min, $max[, $pad_string[, $pad_type]]);
Sanitizes the value to truncate values longer than the maximum.
$filter->sanitize('field')->to('strlenMax', $max);
Sanitizes the value to str_pad()
values shorter than the minimum.
$filter->sanitize('field')->to('strlenMin', $min[, $pad_string[, $pad_type]]);
Sanitizes the value to titlecase (eg. "Title Case").
$filter->sanitize('field')->to('titlecase');
Sanitizes the value to trim()
it. Optionally specify characters to trim.
$filter->sanitize('field')->to('trim', $chars);
Sanitizes the value to all uppercase characters.
$filter->sanitize('field')->to('uppercase');
Sanitizes the value to begin with an uppercase character.
$filter->sanitize('field')->to('uppercaseFirst');
Sanitizes to the specified value.
$filter->sanitize('field')->to('value', $other_value);
Sanitizes the value to remove non-word characters.
$filter->sanitize('field')->to('word');