SPHPlayground API
SPHPlayground
sphplayground sphplayground

Data Filtering

PREFACE:

One of the most amazing strengths of PHP is its convenience. However this has worked against PHP as numerous coders have forgotten any security to establish safety or fails to offer the adroitness to make a class to validate their variables from end users. [1]

The PHP filter extension filters data by either validating or sanitizing it. This is especially useful when the data source contains unknown (or foreign) data, like user supplied input. For example, this data may come from an HTML form. [2]

Filter Classes in SPHPlayground offer simple object oriented interface to filtering and validation.

All SPHPlayground filters implement the Filter interface. Build-in filters focus on filtering arrays and scalar values.

Definition a data filter:

  1. All Filter implementations should accept any type of input variable
  2. An implementation should never throw an exception or produce PHP errors or PHP warnings for any type of input data
  3. Otherwise the implementation of the functionality is totally unrestricted
  4. Because of the above rules these filters are NOT necessarily SAFE

Sanitizing filters

These filters sanitize scalar values or an array of scalars. Similar results can be achieved by using PHP's filter extension.

An ArrayFilter filters an array of valiables. It returns filtered values as an array. Individual key -> value pairs are filtered using specified filters like:

Special filters

SPHPlayground has a couple of special filters.

Filters for development and testing

HtmlIntender indents HTML. It uses Dindent, and thus it will not sanitize or otherwise manipulate your output beyond indentation.

SQLFormatter indents SQL statement strings. It uses Doctrine SqlFormatter. This filter will not sanitize or otherwise manipulate the output beyond indentation.

Special numeric filters