php-extended/php-html-object

A library that implements the php-extended/php-html-interface interface library


Keywords
php, tree, html, object, implementation
License
MIT

Documentation

php-html-object

A library that implements the php-extended/php-html-interface interface library.

Installation

The installation of this library is made via composer. Download composer.phar from their website. Then add to your composer.json :

	"require": {
		...
		"php-extended/php-html-object": "^2",
		...
	}

Then run php composer.phar update to install this library. The autoloading of all classes of this library is made through composer's autoloader.

Basic Usage

To build a html tree, just use the collection node and the single nodes :


use PhpExtended\Html\HtmlAbstractNode;
use PhpExtended\Html\HtmlCollectionNode;
use PhpExtended\Html\HtmlDoctypeNode;
use PhpExtended\Html\HtmlTextNode;

$document = new HtmlCollectionNode(HtmlAbstractNode::TYPE_DOCUMENT);
$doctype = new HtmlDoctypeNode();
$document->addChild($doctype);
$html = new HtmlCollectionNode('html');
$document->addChild($html);
$body = new HtmlCollectionNode('body');
$html->addChild($body);
$h1 = new HtmlCollectionNode('h1', ['class' => 'title']);
$body->addChild($h1);
$title = new HtmlTextNode('>> Example Title <<');
$h1->addChild($title);
$text = new HtmlCollectionNode('p', [], [new HtmlTextNode('This is an &xample.')]);
$body->addChild($text);

$document->__toString();
// <!DOCTYPE html><html><body><h1 class="title">&gt;&gt; Example Title &lt;&lt;</h1><p>This is an &amp;xample.</p></body></html>

License

MIT (See license file).