Documentation

Enc
in package

Encoding of data for various outputs

Table of Contents

Methods

cleanfunky()  : string
Strip funky stuff from a string.
html()  : string
Encoding for HTML Existing HTML entities in a string will be double-encoded
htmlNoDup()  : string
Encoding for HTML, but safe from double-encoding of existing entities
httpfield()  : string
Encoding for field name in a form element
id()  : string
Encoding for ID or CLASS attributes
js()  : mixed
Encoding for going inside a JS string
jsdate()  : string|null
Returns the JS code needed to initialise a Date() object with the specified date.
url()  : string
Encoding for a part of a URL (i.e. GET parameter value
urlname()  : string
Nice name of something when dealing with friendly URLs.
xml()  : string
Encoding for XML

Methods

cleanfunky()

Strip funky stuff from a string.

public static cleanfunky(mixed $value) : string

Funky stuff is anything in the ASCII control plane (0x00 - 0x1F) Except tab, line feed, carriage return

Parameters
$value : mixed
Return values
string

html()

Encoding for HTML Existing HTML entities in a string will be double-encoded

public static html(string $value) : string
Parameters
$value : string

The text to encode. This should be plain (i.e. non-HTML) text

Tags
example

$html = Enc::html('A & B'); // returns A & B

$bad_html = Enc::html('A & B'); // don't do this; returns A & B

Return values
string

htmlNoDup()

Encoding for HTML, but safe from double-encoding of existing entities

public static htmlNoDup(string $value) : string
Parameters
$value : string

The text to encode. This should be plain (i.e. non-HTML) text

Tags
example

$html = Enc::html('A & B'); // returns A & B

$html = Enc::html('A & B'); // this is fine; returns A & B

Return values
string

httpfield()

Encoding for field name in a form element

public static httpfield(string $value) : string
Parameters
$value : string

The value to encode

Return values
string

id()

Encoding for ID or CLASS attributes

public static id(string $value) : string
Parameters
$value : string

The value to encode

Return values
string

js()

Encoding for going inside a JS string

public static js(string $value) : mixed
Parameters
$value : string

The value to encode

jsdate()

Returns the JS code needed to initialise a Date() object with the specified date.

public static jsdate(string|array<string|int, mixed> $value[, string $from = 'mysql' ]) : string|null

This should only be used for dates. For times or date-times, use a different function.

From types: 'mysql' - a mysql-formatted date in the form YYYY-MM-DD 'array' - an array [ , , ]

Parameters
$value : string|array<string|int, mixed>

The value to convert.

$from : string = 'mysql'

What format the date was in origanally.

Return values
string|null —

JavaScript snippet for the given date or NULL if the input value is invalid

url()

Encoding for a part of a URL (i.e. GET parameter value

public static url(string $value) : string
Parameters
$value : string

The value to encode

Return values
string

urlname()

Nice name of something when dealing with friendly URLs.

public static urlname(string $value[, string $delimiter = '-' ]) : string

This provides the backend for Slug::create

Parameters
$value : string

The value to encode

$delimiter : string = '-'
Return values
string

xml()

Encoding for XML

public static xml(string $value) : string
Parameters
$value : string

The value to encode

Return values
string
On this page

Search results