\Nano4\Utils\HTMLElement

Progmatically create HTML structures using PHP objects.

Summary

Methods
Properties
Constants
__construct()
add()
__call()
to_xml()
to_html()
__toString()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
$xml
$parent
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$xml

$xml : 

Type

$parent

$parent : 

Type

Methods

__construct()

__construct(mixed  $xml, array  $opts = array()) 

Build a new HTML\Element object.

Parameters

mixed $xml

The tag name, or initial XML data.

array $opts

Options for constructing the object.

Options:

'parent' The parent Element object. If this is set, then the $xml parameter must be a simple tag name.

'content' Used if 'parent' is set, to optionally set the body content of the new tag.

'attrs' If set, this must be a PHP array. Associative members are name => value mapping. Flat (i.e. numerically indexed) members are boolean attributes to set (i.e. selected="selected" style.)

If there is no 'parent' option, then the $xml variable can be in a few different formats:

A simple tag name 'h1' An XML string '

    ' A SimpleXMLElement object A DOMElement or DOMDocument object

add()

add(mixed  $element) 

Add an existing HTML or XML element.

Parameters

mixed $element

The element we want to add.

The $element variable can be one of the following:

Another HTML\Element object. A SimpleXMLElement object. A DOMElement or DOMDocument object. An XML string '

    '

__call()

__call(  $tag, array  $params) 

Create a child HTML element.

Parameters

$tag
array $params

Content and attributes.

This __call function handles the magic of adding new children. Basically, any unknown method is assumed to be a child tag name.

The parameters are handled depending on what they are.

If a parameter is a string, it's considered body content. Multiple string parameters will be joined using newlines as a separator.

If a parameter is an array, it's assumed to be a set of attributes. Multiple arrays will be joined using array addition.

to_xml()

to_xml(  $opts = array()) 

Return the XML string representing our element.

Parameters

$opts

to_html()

to_html(  $opts = array()) 

Return the HTML string representing our element.

This strips the XML declarator, and trims the string.

It can optionally add an HTML doctype declarator. You can specify the declarator (the part after !DOCTYPE) as a string, or use one of the following numeric values:

4.0 HTML 4.01 Transitional -4.0 HTML 4.01 Strict 1.0 XHTML 1.0 Transitional -1.0 XHTML 1.0 Strict 1.1 XHTML 1.1 -1.1 XHTML 1.1 (alias) 5.0 HTML 5 -5.0 HTML 5 (alias)

The only number that requires a decimal value is 1.1, the rest the decimal place is optional and only included for formatting.

Parameters

$opts

__toString()

__toString() 

If an HTML\Element object is used in a string context, it will return an HTML string, see to_html() for details.

offsetExists()

offsetExists(  $offset) 

Is an attribute set on our element?

Parameters

$offset

offsetGet()

offsetGet(  $offset) 

Get an attribute.

Parameters

$offset

offsetSet()

offsetSet(  $offset,   $value) 

Set an attribute.

Parameters

$offset
$value

offsetUnset()

offsetUnset(  $offset) 

Unset an attribute.

Parameters

$offset