php-extended / php-html-object
A library that implements the php-extended/php-html-interface interface library
7.0.6
2024-07-31 13:51 UTC
Requires
Requires (Dev)
- dev-master
- 7.0.6
- 7.0.5
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.1.7
- 6.1.6
- 6.1.5
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.0
- 5.0.1
- 5.0.0
- 4.0.1
- 4.0.0
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.16
- 3.1.15
- 3.1.14
- 3.1.13
- 3.1.12
- 3.1.11
- 3.1.10
- 3.1.9
- 3.1.8
- 3.1.7
- 3.1.6
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.19
- 2.2.18
- 2.2.17
- 2.2.16
- 2.2.15
- 2.2.14
- 2.2.13
- 2.2.12
- 2.2.11
- 2.2.10
- 2.2.9
- 2.2.8
- 2.2.7
- 2.2.6
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
This package is auto-updated.
Last update: 2024-10-01 00:08:43 UTC
README
A library that implements the php-extended/php-html-interface interface library.
Installation
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 ^7
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">>> Example Title <<</h1><p>This is an &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
License
MIT (See license file).