All Projects → ivopetkov → Html5 Dom Document Php

ivopetkov / Html5 Dom Document Php

Licence: mit
A better HTML5 parser for PHP.

Projects that are alternatives of or similar to Html5 Dom Document Php

Lua Gumbo
Moved to https://gitlab.com/craigbarnes/lua-gumbo
Stars: ✭ 116 (-75.68%)
Mutual labels:  parser, html5, dom
Html React Parser
📝 HTML to React parser.
Stars: ✭ 846 (+77.36%)
Mutual labels:  parser, dom
Cheerio
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
Stars: ✭ 24,616 (+5060.59%)
Mutual labels:  parser, dom
Hpq
Utility to parse and query HTML into an object shape
Stars: ✭ 82 (-82.81%)
Mutual labels:  parser, dom
Gomponents
Declarative view components in Go, that can render to HTML5.
Stars: ✭ 49 (-89.73%)
Mutual labels:  html5, dom
Scalajs Bootstrap
Scala.js bootstrap components
Stars: ✭ 55 (-88.47%)
Mutual labels:  html5, dom
Sequential
An environment to visualize JavaScript code execution in a browser
Stars: ✭ 74 (-84.49%)
Mutual labels:  parser, html5
Anglesharp.js
👼 Extends AngleSharp with a .NET-based JavaScript engine.
Stars: ✭ 68 (-85.74%)
Mutual labels:  parser, dom
Parse5
HTML parsing/serialization toolset for Node.js. WHATWG HTML Living Standard (aka HTML5)-compliant.
Stars: ✭ 2,778 (+482.39%)
Mutual labels:  parser, html5
Redom
Tiny (2 KB) turboboosted JavaScript library for creating user interfaces.
Stars: ✭ 3,123 (+554.72%)
Mutual labels:  html5, dom
Frontendwingman
Frontend Wingman, Learn frontend faster!
Stars: ✭ 315 (-33.96%)
Mutual labels:  html5, dom
Curtainsjs
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.
Stars: ✭ 1,039 (+117.82%)
Mutual labels:  html5, dom
Slim.js
Fast & Robust Front-End Micro-framework based on modern standards
Stars: ✭ 789 (+65.41%)
Mutual labels:  html5, dom
Web Template
web-template.js 是一款基于 ES6 模板字符串解析的模板引擎。
Stars: ✭ 67 (-85.95%)
Mutual labels:  html5, dom
Anglesharp
👼 The ultimate angle brackets parser library parsing HTML5, MathML, SVG and CSS to construct a DOM based on the official W3C specifications.
Stars: ✭ 4,018 (+742.35%)
Mutual labels:  parser, dom
Selectolax
Python binding to Modest engine (fast HTML5 parser with CSS selectors).
Stars: ✭ 368 (-22.85%)
Mutual labels:  parser, html5
Latex.js
JavaScript LaTeX to HTML5 translator
Stars: ✭ 374 (-21.59%)
Mutual labels:  parser, html5
Gtsummary
Presentation-Ready Data Summary and Analytic Result Tables
Stars: ✭ 450 (-5.66%)
Mutual labels:  html5
Tony
An Elegant WordPress Theme Based on ✌️Vue.js | 基于 Vue.js 的简洁一般强大的 WordPress 单栏博客主题
Stars: ✭ 462 (-3.14%)
Mutual labels:  html5
Fasthan
fastHan是基于fastNLP与pytorch实现的中文自然语言处理工具,像spacy一样调用方便。
Stars: ✭ 449 (-5.87%)
Mutual labels:  parser

HTML5DOMDocument

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

Build Status Latest Stable Version codecov.io License Codacy Badge

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

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
require 'vendor/autoload.php';

$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('<!DOCTYPE html><html><body>Hello</body></html>');
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('<!DOCTYPE html><html><body><h1>Hello</h1><div class="content">This is some text</div></body></html>');

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

echo $dom->querySelector('.content')->outerHTML;
// <div class="content">This is some text</div>

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

$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('
    <!DOCTYPE html>
    <html>
        <head>
            <style>...</style>
        </head>
        <body>
            <h1>Hello</h1>
        </body>
    </html>
');

$dom->insertHTML('
    <html>
        <head>
            <script>...</script>
        </head>
        <body>
            <div>This is some text</div>
        </body>
    </html>
');

echo $dom->saveHTML();
// <!DOCTYPE html>
//     <html>
//         <head>
//             <style>...</style>
//             <script>...</script>
//         </head>
//         <body>
//             <h1>Hello</h1>
//             <div>This is some text</div>
//         </body>
//     </html>

Manipulate the values of the class attribute of an element:

$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML('<div class="class1"></div>');

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].