php-extended/php-html-object
最新稳定版本:8.0.11
Composer 安装命令:
composer require php-extended/php-html-object
包简介
A library that implements the php-extended/php-html-interface interface library
README 文档
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.pharfrom their website. - Then run the following command to install this library as dependency :
php composer.phar php-extended/php-html-object ^8
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).
统计信息
- 总下载量: 49.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 18
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-07