Sections

Filter Component


Built-in Sanitizers

Where appropriate, the sanitizers will cast the value to the type expected. For example the absint sanitizer will remove all non numeric characters from the input, cast the input to an integer and return its absolute value. {: .alert .alert-warning }

The following are the built-in filters provided by this component:

absint

AbsInt( mixed $input ): int

Removes any non numeric characters, casts the value to integer and returns its absolute value. Internally it uses filter_var for the integer part, intval for casting and absint.

alnum

Alnum( mixed $input ): string | array

Removes all characters that are not numbers or characters of the alphabet. It uses preg_replace which can also accept arrays of strings as the parameters.

alpha

Alpha( mixed $input ): string | array

Removes all characters that are not characters of the alphabet. It uses preg_replace which can also accept arrays of strings as the parameters.

bool

BoolVal( mixed $input ): bool

Casts the value to a boolean.

It also returns true if the value is:

  • true
  • on
  • yes
  • y
  • 1

It also returns false if the value is:

  • false
  • off
  • no
  • n
  • 0

email

Email( mixed $input ): string

Removes all characters except letters, digits and !#$%&*+-/=?^_`{\|}[email protected][]. Internally it uses filter_var.

float

FloatVal( mixed $input ): float

Removes all characters except digits, dot, plus and minus sign and casts the value as a double. Internally it uses filter_var and (double).

int

IntVal( mixed $input ): int

Remove all characters except digits, plus and minus sign abd casts the value as an integer. Internally it uses filter_var and (int).

lower

Lower( mixed $input ): string

Converts all characters to lowercase. If the mbstring extension is loaded, it will use mb_convert_case to perform the transformation. As a fallback it uses the strtolower PHP function, with utf8_decode.

lowerFirst

LowerFirst( mixed $input ): string

Converts the first character of the input to lower case. Internally it uses lcfirst.

regex

Regex( mixed $input, mixed $pattern, mixed $replace ): string

Performs a regex replacement on the input using a pattern and the replace parameter. Internally it uses preg_replace.

remove

Remove( mixed $input, mixed $remove ): string

Performs a replacement on the input, replacing the replace parameter with an empty string, effectively removing it. Internally it uses str_replace.

replace

Replace( mixed $input, mixed $from, mixed $to ): string

Performs a replacement on the input based on the from and to passed parameters. Internally it uses str_replace.

special

Special( mixed $input ): string

Escapes all HTML characters of the input, as well as '"<>& and characters with ASCII value less than 32. Internally it uses filter_var.

specialFull

SpecialFull( mixed $input ): string

Converts all the special characters of the input to HTML entities (both double and single quotes). Internally it uses filter_var.

string

StringVal( mixed $input ): string

Strip tags and encode HTML entities, including single and double quotes. Internally it uses filter_var.

striptags

StripTags( mixed $input ): int

Removes all HTML and PHP tags from the input. Internally it uses strip_tags.

trim

Trim( mixed $input ): string

Removes all leading and trailing whitespace from the input. Internally it uses trim.

upper

Upper( mixed $input ): string

Converts all characters to uppercase. If the mbstring extension is loaded, it will use mb_convert_case to perform the transformation. As a fallback it uses the strtoupper PHP function, with utf8_decode.

upperFirst

UpperFirst( mixed $input ): string

Converts the first character of the input to upper case. Internally it uses ucfirst.

upperWords

UpperWords( mixed $input ): string

Converts into uppercase the first character of each word from the input. Internally it uses ucwords.

url

Url( mixed $input ): string

Constants are available and can be used to define the type of sanitizing required:

<?php

const FILTER_ABSINT      = 'absint';
const FILTER_ALNUM       = 'alnum';
const FILTER_ALPHA       = 'alpha';
const FILTER_BOOL        = 'bool';
const FILTER_EMAIL       = 'email';
const FILTER_FLOAT       = 'float';
const FILTER_INT         = 'int';
const FILTER_LOWER       = 'lower';
const FILTER_LOWERFIRST  = 'lowerFirst';
const FILTER_REGEX       = 'regex';
const FILTER_REMOVE      = 'remove';
const FILTER_REPLACE     = 'replace';
const FILTER_SPECIAL     = 'special';
const FILTER_SPECIALFULL = 'specialFull';
const FILTER_STRING      = 'string';
const FILTER_STRIPTAGS   = 'striptags';
const FILTER_TRIM        = 'trim';
const FILTER_UPPER       = 'upper';
const FILTER_UPPERFIRST  = 'upperFirst';
const FILTER_UPPERWORDS  = 'upperWords';
const FILTER_URL         = 'url';