Convert
class Convert
Library of conversion functions, implemented as static methods.
The methods are all of the form (format)2(format), where the format is one of
raw: A UTF8 string attr: A UTF8 string suitable for inclusion in an HTML attribute js: A UTF8 string suitable for inclusion in a double-quoted javascript string.
array: A PHP associative array json: JavaScript object notation
html: HTML source suitable for use in a page or email text: Plain-text content, suitable for display to a user as-is, or insertion in a plaintext email.
Objects of type {@link ViewableData} can have an "escaping type", which determines if they are automatically escaped before output by {@link SSViewer}.
Methods
Convert a value to be suitable for an XML attribute.
Convert a value to be suitable for an HTML attribute.
Convert a value to be suitable for an HTML ID attribute. Replaces non supported characters with a space.
Convert a value to be suitable for an HTML ID attribute. Replaces non supported characters with an underscore.
Ensure that text is properly escaped for XML.
Ensure that text is properly escaped for Javascript.
Encode a value as a JSON encoded string. You can optionally pass a bitmask of JSON constants as options through to the encode function.
Safely encodes a value (or list of values) using the current database's safe string encoding method
Safely encodes a SQL symbolic identifier (or list of identifiers), such as a database, table, or column name. Supports encoding of multi identfiers separated by a delimiter (e.g. ".")
Convert XML to raw text.
Converts an XML string to a PHP array See http://phpsecurity.readthedocs.org/en/latest/Injection-Attacks.html#xml-external-entity-injection
Create a link if the string is a valid URL
Simple conversion of HTML to plaintext.
There are no real specifications on correctly encoding mailto-links, but this seems to be compatible with most of the user-agents.
Convert a string (normally a title) to a string suitable for using in urls and other html attributes. Uses {@link URLSegmentFilter}.
Normalises newline sequences to conform to (an) OS specific format.
Encode a value into a string that can be used as part of a filename.
Decode a value that was encoded with Convert::base64url_encode.
Converts upper camel case names to lower camel case, with leading upper case characters replaced with lower case.
Turn a memory string, such as 512M into an actual number of bytes.
No description
Convert slashes in relative or asolute filesystem path. Defaults to DIRECTORY_SEPARATOR
Details
at line 39
static array|string
raw2att(array|string $val)
Convert a value to be suitable for an XML attribute.
at line 50
static array|string
raw2htmlatt(string|array $val)
Convert a value to be suitable for an HTML attribute.
at line 65
static array|string
raw2htmlname(array|string $val)
Convert a value to be suitable for an HTML ID attribute. Replaces non supported characters with a space.
at line 88
static array|string
raw2htmlid(array|string $val)
Convert a value to be suitable for an HTML ID attribute. Replaces non supported characters with an underscore.
at line 115
static array|string
raw2xml(array|string $val)
Ensure that text is properly escaped for XML.
at line 133
static array|string
raw2js(array|string $val)
Ensure that text is properly escaped for Javascript.
at line 159
static string
raw2json(mixed $val, int $options)
deprecated
deprecated 4.4.0:5.0.0 Use json_encode() instead
Encode a value as a JSON encoded string. You can optionally pass a bitmask of JSON constants as options through to the encode function.
at line 174
static string
array2json(array $val, int $options)
deprecated
deprecated 4.4.0:5.0.0 Use json_encode() instead
Encode an array as a JSON encoded string.
at line 191
static string|array
raw2sql(mixed|array $val, boolean $quoted = false)
Safely encodes a value (or list of values) using the current database's safe string encoding method
at line 217
static string
symbol2sql(string|array $identifier, string $separator = '.')
Safely encodes a SQL symbolic identifier (or list of identifiers), such as a database, table, or column name. Supports encoding of multi identfiers separated by a delimiter (e.g. ".")
at line 229
static array|string
xml2raw(mixed $val)
Convert XML to raw text.
at line 253
static object|boolean
json2obj(string $val)
deprecated
deprecated 4.4.0:5.0.0 Use json_decode() instead
Convert a JSON encoded string into an object.
at line 267
static array|boolean
json2array(string $val)
deprecated
deprecated 4.4.0:5.0.0 Use json_decode() instead
Convert a JSON string into an array.
at line 286
static array
xml2array(string $val, boolean $disableDoctypes = false, boolean $disableExternals = false)
Converts an XML string to a PHP array See http://phpsecurity.readthedocs.org/en/latest/Injection-Attacks.html#xml-external-entity-injection
at line 358
static string
linkIfMatch(string $string)
Create a link if the string is a valid URL
at line 376
static string
html2raw(string $data, bool $preserveLinks = false, int $wordWrap, array $config = null)
Simple conversion of HTML to plaintext.
at line 459
static string
raw2mailto($data)
There are no real specifications on correctly encoding mailto-links, but this seems to be compatible with most of the user-agents.
Does nearly the same as rawurlencode(). Please only encode the values, not the whole url, e.g. "mailto:test@test.com?subject=" . Convert::raw2mailto($subject)
at line 475
static string
raw2url(string $title)
Convert a string (normally a title) to a string suitable for using in urls and other html attributes. Uses {@link URLSegmentFilter}.
at line 490
static string
nl2os(string $data, string $nl = PHP_EOL)
Normalises newline sequences to conform to (an) OS specific format.
at line 502
static string
base64url_encode(mixed $val)
Encode a value into a string that can be used as part of a filename.
All string data must be UTF-8 encoded.
at line 513
static mixed
base64url_decode(string $val)
Decode a value that was encoded with Convert::base64url_encode.
at line 534
static string
upperCamelToLowerCamel($str)
Converts upper camel case names to lower camel case, with leading upper case characters replaced with lower case.
Tries to retain word case.
Examples: - ID => id - IDField => idField - iDField => iDField
at line 572
static int
memstring2bytes(string $memString)
Turn a memory string, such as 512M into an actual number of bytes.
Preserves integer values like "1024" or "-1"
at line 593
static string
bytes2memstring(float $bytes, int $decimal)
at line 615
static string
slashes(string $path, string $separator = DIRECTORY_SEPARATOR, bool $multiple = true)
Convert slashes in relative or asolute filesystem path. Defaults to DIRECTORY_SEPARATOR