abstract class Utils

Methods

static string[]
getAttributeValues(string $xml, string $tagName, string $attrName)

Return every value used in given attribute from given tag

static string
encodeUnicodeSupplementaryCharacters(string $str)

Replace Unicode characters outside the BMP with XML entities

static string
removeFormatting(string $xml)

Strip the formatting of an intermediate representation and return plain text

static string
removeTag(string $xml, string $tagName, int $nestingLevel = 0)

Remove all tags at given nesting level

static string
replaceAttributes(string $xml, string $tagName, callable $callback)

Replace the attributes of all tags of given name in given XML

static string
encodeUnicodeSupplementaryCharactersCallback(array $m)

Encode given Unicode character into an XML entity

static DOMDocument
loadXML(string $xml)

Create a return a new DOMDocument loaded with given XML

static array
parseAttributes(string $xml)

Parse the attributes contained in given XML

static string
saveXML(DOMDocument $dom)

Serialize given DOMDocument

static string
serializeAttributes(array $attributes)

Serialize an array of attribute values

Details

at line 25
static string[] getAttributeValues(string $xml, string $tagName, string $attrName)

Return every value used in given attribute from given tag

Will include duplicate values

Parameters

string $xml

Parsed text

string $tagName

Target tag's name

string $attrName

Target attribute's name

Return Value

string[]

Attribute values

at line 47
static string encodeUnicodeSupplementaryCharacters(string $str)

Replace Unicode characters outside the BMP with XML entities

Parameters

string $str

Original string

Return Value

string

String with SMP characters encoded

at line 64
static string removeFormatting(string $xml)

Strip the formatting of an intermediate representation and return plain text

This will remove start tags and end tags but will keep the text content of everything else

Parameters

string $xml

Intermediate representation

Return Value

string

Plain text

at line 84
static string removeTag(string $xml, string $tagName, int $nestingLevel = 0)

Remove all tags at given nesting level

Parameters

string $xml

Intermediate representation

string $tagName

Tag's name (case-sensitive)

int $nestingLevel

Minimum nesting level

Return Value

string

Updated intermediate representation

at line 112
static string replaceAttributes(string $xml, string $tagName, callable $callback)

Replace the attributes of all tags of given name in given XML

Parameters

string $xml

Original XML

string $tagName

Target tag's name

callable $callback

Callback used to process attributes. Receives the old attributes as an array, should return the new attributes as an array

Return Value

string

Modified XML

at line 141
static protected string encodeUnicodeSupplementaryCharactersCallback(array $m)

Encode given Unicode character into an XML entity

Parameters

array $m

Array of captures

Return Value

string

Encoded character

at line 155
static protected DOMDocument loadXML(string $xml)

Create a return a new DOMDocument loaded with given XML

Parameters

string $xml

Source XML

Return Value

DOMDocument

at line 172
static protected array parseAttributes(string $xml)

Parse the attributes contained in given XML

Parameters

string $xml

XML string, normally a start tag

Return Value

array

Associative array of attribute values

at line 193
static protected string saveXML(DOMDocument $dom)

Serialize given DOMDocument

Parameters

DOMDocument $dom

Return Value

string

at line 204
static protected string serializeAttributes(array $attributes)

Serialize an array of attribute values

Parameters

array $attributes

Associative array of attribute values

Return Value

string

Attributes, sorted by name and serialized to XML