Parses HTML into a tree of tags.

package XenForo_Html

 Methods

Constructor.

__construct(string $html) 

Sets up HTML.

Parameters

$html

string

HTML to parse

Appends text to the current tag.

appendText(string | false $text) 

Text is cleaned of HTML entities first.

Parameters

$text

stringfalse

Text to append; false is ignored

Decodes HTML entities in a string.

decodeEntities(string $string) : string

Note that non-breaking spaces are treated as normal spaces.

Parameters

$string

string

Returns

stringDecoded string

Parses the HTML.

parse() : \XenForo_Html_Tag

Returns

\XenForo_Html_TagThe root tag of the tree. This tag isn't really in the tree, so traversal should start with its children.

Parses CSS into its component rules.

parseCss(string $css) : array

Parameters

$css

string

Returns

arrayKey-value rule pairs

Peak at the current character without changing the current position.

peak() : false | string

Returns

falsestringFalse if past the end; character otherwise

Debug helper to print the tag tree in HTML format.

printTags(\XenForo_Html_Tag $tag, string $prefix) 

Parameters

$tag

\XenForo_Html_Tag

Current/root tag

$prefix

string

Prefix for each line

Push a tag close to the current tag and have it return the new value for the current tag.

pushTagClose(string $tagName) 

Parameters

$tagName

string

Push a tag open.

pushTagOpen(string $tagName, array $attributes) : \XenForo_Html_Tag

Parameters

$tagName

string

$attributes

array

Key-value attributes; cleaned of HTML entities within function

Returns

\XenForo_Html_TagChild tag that was added

Read until one of the characters is found.

readUntilCharacters(string $characters) : false | string

Parameters

$characters

string

List of characters

Returns

falsestringFalse if the none of the characters are found; otherwise, text to first character found

Read until the end of the string.

readUntilEnd() : false | string

Returns

falsestringFalse if at the end; otherwise, text until end

Read until (but not including) the given string is found.

readUntilString(string $string) : false | string

Parameters

$string

string

Returns

falsestringFalse if the string is not found; otherwise, text to string

Skip over any amount of whitespace.

skipWhiteSpace() 

Function is called when entering the attribute state.

stateAttribute(array $attributes) : boolean

Parameters

$attributes

array

Existing attribute list. New attributes are pushed onto this.

Returns

booleanIf false is returned, the containing tag is considered invalid and treated as text

Function is called when entering the tag state.

stateTag() : boolean

The opening < has been found and passed.

Returns

booleanTrue if tag was parsed; if false, the tag is treated as plain text

Read the current character and advance one position.

step() : string

Returns

string

stepBack()

stepBack() 

 Properties

 

$_currentTag : \XenForo_Html_Tag
 

$_html : string
 

$_length : integer
 

$_position : integer
 

$_rootTag : \XenForo_Html_Tag