popphp/pop-dom
Composer 安装命令:
composer require popphp/pop-dom
包简介
Pop DOM Component for Pop PHP Framework
README 文档
README
Overview
pop-dom is a component for generating, rendering and parsing DOM documents and elements. With it,
you can easily create or parse document nodes and their children and have control over node content and
attributes.
pop-dom is a component of the Pop PHP Framework.
Install
Install pop-dom using Composer.
composer require popphp/pop-dom
Or, require it in your composer.json file
"require": {
"popphp/pop-dom" : "^4.0.7"
}
Quickstart
A simple DOM node fragment
use Pop\Dom\Child; $div = new Child('div'); $h1 = new Child('h1', 'This is a header'); $p = new Child('p'); $p->setNodeValue('This is a paragraph.'); $div->addChildren([$h1, $p]); echo $div;
<div> <h1>This is a header</h1> <p class="paragraph">This is a paragraph.</p> </div>
Building a full DOM document
use Pop\Dom\Document; use Pop\Dom\Child; // Title element $title = new Child('title', 'This is the title'); // Meta tag $meta = new Child('meta'); $meta->setAttributes([ 'http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8' ]); // Head element $head = new Child('head'); $head->addChildren([$title, $meta]); // Some body elements $h1 = new Child('h1', 'This is a header'); $p = new Child('p', 'This is a paragraph.'); $div = new Child('div'); $div->setAttribute('id', 'content'); $div->addChildren([$h1, $p]); // Body element $body = new Child('body'); $body->addChild($div); // Html element $html = new Child('html'); $html->addChildren([$head, $body]); // Create and render the DOM document with HTTP headers $doc = new Document(Document::HTML, $html); echo $doc;
<!DOCTYPE html> <html> <head> <title>This is the title</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <div id="content"> <h1>This is a header</h1> <p>This is a paragraph.</p> </div> </body> </html>
Parsing
You can parse from a string of XML or HTML and it will return an object of Child elements that you can further manipulate or edit to then output:
$html = <<<HTML <html> <head> <title>Hello World Title</title> </head> <body> <h1 class="top-header" id="header">Hello World Header</h1> <p>How are <em>YOU</em> doing <strong><em>today</em></strong>???</p> <p class="special-p">Some <strong class="bold">more</strong> text.</p> </body> </html> HTML; $doc = new Document(Document::HTML); $doc->addChild(Child::parseString($html)); echo $doc;
And you can parse from a file as well:
$children = Child::parseFile('index.html');
popphp/pop-dom 适用场景与选型建议
popphp/pop-dom 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.6k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2014 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「dom」 「document object model」 「pop」 「pop php」 「dom generation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 popphp/pop-dom 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 popphp/pop-dom 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 popphp/pop-dom 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A library that provides basic utilities for creating HTML documents.
A bridge between SimpleXML and the DOM extension, plus a bunch of convenience methods
BigPipe: Pipelining web pages for high performance built in PHP.
Invalidity check of documents in the database of Ministry of the Interior of the Czech Republic
Load DOM document safety
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 21.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 23
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-12-08