toolkit

San

Sanitizes untrusted input into clean text, email, url and similar values.

San:: Phlat\Toolkit\San 9 methods

Strings 4

  • text Trims and strips all HTML tags.
  • term Free text for a `search=` condition: tags stripped, and commas (the query DSL's separator, which has no escape) and any run of whitespace flattened to one space.
  • html Escapes HTML special characters for safe output.
  • filename The stem slugged, the last extension lowercased to a-z and 0-9: "My Photo (1).JPG" becomes "my-photo-1.jpg".

Scalars 3

  • int Returns null if the value is not numeric.
  • float Returns null if the value is not numeric.
  • bool Coerces to bool - accepts true/false/1/0/yes/no/on/off.

Network 2

  • email Returns null if not a valid email address.
  • url Returns null unless a valid http(s) or mailto URL - FILTER_VALIDATE_URL alone also passes javascript://host/%0Aalert(1), vbscript:// and file:// URLs.

Strings

San::text(string $value): string

Trims and strips all HTML tags.

Parameters (1)
$value string

Returns string

phlat/src/Toolkit/San.php:17
San::term(string $value): string

Free text for a `search=` condition: tags stripped, and commas (the query DSL's separator, which has no escape) and any run of whitespace flattened to one space.

Parameters (1)
$value string

Returns string

phlat/src/Toolkit/San.php:23
San::html(string $value): string

Escapes HTML special characters for safe output.

Parameters (1)
$value string

Returns string

phlat/src/Toolkit/San.php:29
San::filename(string $value): string

The stem slugged, the last extension lowercased to a-z and 0-9: "My Photo (1).JPG" becomes "my-photo-1.jpg".

Empty if no stem or extension survives.

Parameters (1)
$value string

Returns string

phlat/src/Toolkit/San.php:35

Scalars

int

San::int(mixed $value): ?int

Returns null if the value is not numeric.

Parameters (1)
$value mixed

Returns ?int

phlat/src/Toolkit/San.php:45
San::float(mixed $value): ?float

Returns null if the value is not numeric.

Parameters (1)
$value mixed

Returns ?float

phlat/src/Toolkit/San.php:51
San::bool(mixed $value): bool

Coerces to bool - accepts true/false/1/0/yes/no/on/off.

Parameters (1)
$value mixed

Returns bool

phlat/src/Toolkit/San.php:57

Network

San::email(string $value): ?string

Returns null if not a valid email address.

Lowercases on success.

Parameters (1)
$value string

Returns ?string

phlat/src/Toolkit/San.php:65

url

San::url(string $value): ?string

Returns null unless a valid http(s) or mailto URL - FILTER_VALIDATE_URL alone also passes javascript://host/%0Aalert(1), vbscript:// and file:// URLs.

Parameters (1)
$value string

Returns ?string

phlat/src/Toolkit/San.php:72