utilityInputFilter

This class controls all input filters and allows data filtering. This is a wrapper around the PHP filter extension that was introduced with PHP 5.2.0 and is inspired by the ez Components filter system.

Each filter has a variety of options (flags) that can be specified. For a complete list please see the PHP.net documentation for the filter extension.

Example:

$options = array();
$options['options']['min_range'] = 1; 
$options['options']['max_range'] = 10;
$options['flags'] = FILTER_FLAG_ALLOW_OCTAL;

$oFilter = utilityInputFilter::filterInt();
$oFilter->setOptions($options);
$oFilter->doFilter(3);

Note: filtering with FILTER_UNSAFE_RAW may not produce the intended result. In PHP versions <= 5.2.8 filtering HTML strings as unsafe and raw causes any encoded entities to be converted back to the actual character entity e.g. > => > and < => <. So in a HTML block like:

This > that

becomes

This > that

. This appears to all versions of PHP >5.3 as well.

Additional: FILTER_SANITISE_STRING will break none-ASCII characters very badly (e.g. Chinese characters). This is regardless of the FILTER_* options that can be optionally supplied. In these cases you have to fall back to directly accessing _POST/_GET to get the raw data and in keeping with the previous note: FILTER_UNSAFE_RAW will break those strings too.


Methods

public __construct()

Returns new utilityInputFilter

public static filterString()

Return a filter to check string

public static filterUnsafeRaw()

Return a filter to check string

public static filterUnsafeRawArray()

Return a filter to check string

public static filterStringArray()

Return a filter to check string

public static filterInt()

Return a filter to check int

public static filterBoolean()

Return a filter to check boolean

public static filterFloat()

Return a filter to check float

public static filterValidateUrl()

Return a filter to check validate_url

public static filterValidateEmail()

Return a filter to check validate_email

public static filterValidateIp()

Return a filter to check validate_ip

public static filterNumberInt()

Return a filter to check number_int

public static filterNumberFloat()

Return a filter to check number_float

public doFilter([$inData = null])

doFilter will look at the data that is sent and will filter out the correct data and return it

public doGetFilter($inGroup, $inField)

Returns filtered data

public getOptions()

Returns options, null if none set

public setOptions($inOptions)

Set an array of options for the filter

$options = array();
$options['options']['min_range'] = 1; 
$options['options']['max_range'] = 10;
$options['flags'] = FILTER_FLAG_ALLOW_OCTAL;

$oFilter = utilityInputFilter::filterInt();
$oFilter->setOptions($options);

public getFilter()

Returns current filter name

public setFilter($inFilter)

Set new filter

<  1  >