Source Location: /sapphire/core/Convert.php
Inheritance:
Summary: Library of conversion functions, implemented as static methods.
public
static array2json ( $val )
|
Convert an array into a JSON encoded string. |
public
static html2raw ( $data, [$preserveLinks = false], [$wordWrap = 60], [$config = null] )
|
Simple conversion of HTML to plaintext. |
public
static json2array ( $val )
|
Convert a JSON string into an array. |
public
static json2obj ( $val )
|
Convert a JSON encoded string into an object. |
public
static linkIfMatch ( $string )
|
Create a link if the string is a valid URL |
public
static raw2att ( $val )
|
Convert a value to be suitable for an XML attribute. |
public
static raw2htmlatt ( $val )
|
Convert a value to be suitable for an HTML attribute. |
public
static raw2js ( $val )
|
Ensure that text is properly escaped for Javascript. |
public
static raw2json ( $val )
|
Uses the PHP 5.2 native json_encode function if available, otherwise falls back to the Services_JSON class. |
public
static raw2mailto ( $data )
|
There are no real specifications on correctly encoding mailto-links, but this seems to be compatible with most of the user-agents. |
public
static raw2sql ( $val )
|
|
public
static raw2xml ( $val )
|
Ensure that text is properly escaped for XML. |
protected
static recursiveXMLToArray ( $xml )
|
Function recursively run from Convert::xml2array() |
public
static xml2array ( $val )
|
|
public
static xml2raw ( $val )
|
Convert XML to raw text. |
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 ViewableData can have an "escaping type", which determines if they are automatically escaped before output by SSViewer.
[ Top ]
static string array2json(
array
$val)
[line 152]
Convert an array into a JSON encoded string.
$val
- Array to convert
[ Top ]
static void html2raw(
$data
$data, [$preserveLinks
$preserveLinks = false], [$wordwrap
$wordWrap = 60], [
$config = null])
[line 248]
Simple conversion of HTML to plaintext.
$data
- string
$preserveLinks
- boolean
$wordWrap
- array
$config
-
[ Top ]
static array|boolean json2array(
string
$val)
[line 185]
Convert a JSON string into an array.
$val
- JSON string to convert
[ Top ]
static mixed json2obj(
string
$val)
[line 172]
Convert a JSON encoded string into an object.
$val
-
[ Top ]
static A linkIfMatch(
string
$string)
[line 234]
Create a link if the string is a valid URL
$string
- The string to linkify
[ Top ]
static array|string raw2att(
array|string
$val)
[line 31]
Convert a value to be suitable for an XML attribute.
$val
- String to escape, or array of strings
[ Top ]
static array|string raw2htmlatt(
array|string
$val)
[line 51]
Convert a value to be suitable for an HTML attribute.
This is useful for converting human readable values into a value suitable for an ID or NAME attribute.
$val
- String to escape, or array of strings
[ Top ]
static array|string raw2js(
array|string
$val)
[line 84]
Ensure that text is properly escaped for Javascript.
$val
- String to escape, or array of strings
[ Top ]
static string raw2json(
mixed
$val)
[line 104]
Uses the PHP 5.2 native json_encode function if available, otherwise falls back to the Services_JSON class.
$val
-
[ Top ]
static string raw2mailto(
$data
$data)
[line 331]
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)
$data
- string
[ Top ]
static array|string raw2xml(
array|string
$val)
[line 69]
Ensure that text is properly escaped for XML.
$val
- String to escape, or array of strings
[ Top ]
static void recursiveXMLToArray(
$xml)
[line 209]
Function recursively run from Convert::xml2array()
$xml
-
[ Top ]
Comments
Comment policy: Please use comments for tips and corrections about the described functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
blog comments powered by DisqusUse the Silverstripe Forum to ask questions.