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


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

coverage build status


The installation of this library is made via composer and the autoloading of all classes of this library is made through their autoloader.

  • Download composer.phar from their website.
  • Then run the following command to install this library as dependency :
  • php composer.phar php-extended/php-html-object ^6

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();
$html = new HtmlCollectionNode('html');
$body = new HtmlCollectionNode('body');
$h1 = new HtmlCollectionNode('h1', ['class' => 'title']);
$title = new HtmlTextNode('>> Example Title <<');
$text = new HtmlCollectionNode('p', [], [new HtmlTextNode('This is an &xample.')]);

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

To parse html data, do the following :

use PhpExtended\Html\HtmlParser;

$parser = new HtmlParser();
$node = $parser->parse('<!DOCTYPE html><html><head><meta charser="UTF-8" /></head><body><h1>Foo</h1></body></html>');
// $node is not an HtmlCollectionNodeInterface


MIT (See license file).