php-extended / php-html-object
实现php-extended/php-html-interface接口库的库
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-08-31 11:56:10 UTC
README
实现php-extended/php-html-interface接口库的库。
安装
此库的安装通过composer进行,所有类的自动加载都通过其自动加载器完成。
- 从官方网站下载
composer.phar
。 - 然后运行以下命令将此库作为依赖项安装
php composer.phar require php-extended/php-html-object ^7
基本用法
要构建html树,只需使用集合节点和单个节点
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>
要解析html数据,请执行以下操作
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 (见许可证文件)。