PHP 更好的 HTML5 解析器 .
HTML5DOMDocument extends the native DOMDocument library. It fixes some bugs and adds some new functionality.
composer require "ivopetkov/html5-dom-document-php:2.*"Full documentation is available as part of this repository.
Use just like you should use DOMDocument:
loadHTML('Hello');
echo $dom->saveHTML();Query the document with CSS selectors and get the innerHTML and the outerHTML of the elements:
$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):
$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('
Hello
');
$dom->insertHTML('
');
echo $dom->saveHTML();
//
//
//
//
//
//
//
//
Hello
//
//
// Manipulate the values of the class attribute of an element:
$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('
');
echo $dom->querySelector('div')->classList->add('class2');This project is licensed under the MIT License. See the license file for more information.
Feel free to open new issues and contribute to the project. Let's make it awesome and let's do in a positive way.
This library is created and maintained by Ivo Petkov (ivopetkov.com) and some awesome folks.
暂无开放 Issues,或尚未同步最近议题。