百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

html5-dom-document-php

> 前端框架
开源

PHP 更好的 HTML5 解析器 .

603 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

PHP 更好的 HTML5 解析器 .

HTML5DOMDocument

HTML5DOMDocument extends the native DOMDocument library. It fixes some bugs and adds some new functionality.

Why use?

  • Preserves html entities (DOMDocument does not)
  • Preserves void tags (DOMDocument does not)
  • Allows inserting HTML code that moves the correct parts to their proper places (head elements are inserted in the head, body elements in the body)
  • Allows querying the DOM with CSS selectors (currently available: *, tagname, tagname#id, #id, tagname.classname, .classname, tagname.classname.classname2, .classname.classname2, tagname[attribute-selector], [attribute-selector], "div, p", div p, div > p, div + p and p ~ ul.)
  • Adds support for element->classList.
  • Adds support for element->innerHTML.
  • Adds support for element->outerHTML.

Install via Composer

bash
composer require "ivopetkov/html5-dom-document-php:2.*"

Documentation

Full documentation is available as part of this repository.

Examples

Use just like you should use DOMDocument:

php
loadHTML('Hello');
echo $dom->saveHTML();

Query the document with CSS selectors and get the innerHTML and the outerHTML of the elements:

php
$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('
Hello

');

echo $dom->querySelector('h1')->innerHTML;
// Hello

echo $dom->querySelector('.content')->outerHTML;
// 

Insert HTML code into a HTML document (other HTML code):

php
$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('
    
    
        
            

        
        
            
Hello

        
    
');

$dom->insertHTML('
    
        
            

        
        
            

        
    
');

echo $dom->saveHTML();
// 
//     
//         
//             

//             

//         
//         
//             
Hello

//             

//         
//     

Manipulate the values of the class attribute of an element:

php
$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('
');

echo $dom->querySelector('div')->classList->add('class2');

License

This project is licensed under the MIT License. See the license file for more information.

Contributing

Feel free to open new issues and contribute to the project. Let's make it awesome and let's do in a positive way.

Authors

This library is created and maintained by Ivo Petkov (ivopetkov.com) and some awesome folks.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPclasslistdomdomdocumenthtml

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架