Download the PHP package manychois/simdom without Composer
On this page you can find all versions of the php package manychois/simdom. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package simdom
Simdom - A simplified and relaxed DOM structure library
Simdom is a lightweight PHP library designed to make parsing and manipulating DOM documents as straightforward as possible. It requires no external dependencies or extensions.
Without using the built-in PHP DOM extension, Simdom can have its own opinionated appraoch on how HTML documents should be parsed and manipulated. It lets you to work with "non-compliant" HTML structure in a literal and intuitive way.
Before outputing the HTML string of the document, you can call the $document->validate() method to ensure that the document is valid according to the HTML5 specification.
Key differences from the standard HTML5 DOM specification / PHP DOM extension
Simplified node types
Simdom provides 6 node types that form the DOM tree:
Document- The root document nodeDoctype- Document type declarationsElement- HTML elements with attributes and child nodesText- Text content within elementsComment- HTML commentsFragment- Document fragments for grouping nodes
Attributes are not considered as a node type in Simdom, but rather as properties of Element nodes.
CDATA section or processing instructions are not supported, as they would not be valid in HTML5 documents.
Simplified and relaxed DOM structure
- There is no concept of an owner document, meaning nodes can be freely moved between documents.
- There is no concept of namespace.
Document,ElementandFragmentnodes can have child nodes of any type exceptDocumentandFragment, in any order, i.e.:Documentcan holdTextchild.Documentdoes not restrict at most oneDoctypechild, and it does not have to be placed before anyElementchild.Documentdoes not restrict at most oneElementchild.ElementandFragmentcan holdDoctypechild.
- There is no concept of valid element structure, meaning elements can be nested in any way, even if it would not be valid HTML5, i.e.
<table><ul></ul></table>would be parsed as it is. - Misaligned end tags are fixed by finding the last matching start tag, i.e.
<div><span>abc</div>would be parsed as<div><span>abc</span></div>. If there is no matching start tag, the end tag is ignored. <template>elements are treated as a Rawtext type element like<script>or<style>.- Self-closing tag syntax is supported, for example
<div />is parsed as<div></div>. - All element names and attributes names are parsed as their ASCII-lowercase form.
Restrictions
However, there are still some lines you cannot cross in Simdom:
DocumentandFragmenthas no parent node, and cannot be a child of any other node. (InsertingFragmentas a child of any parent node is fine though, as it means inserting theFragment's child nodes.)Elementname and attribute names must conform to the HTML5 specification.Doctypename, public identifier and system identifier must conform to the HTML5 specification.Doctypename must be present if either public or system identifier is present.- No control characters are allowed anywhere, e.g. you cannot inject an delete character (U+007F) to a
Textnode. Commentcannot contain the character sequence-->.- If a
Textnode is under a Rawtext type (e.g.<script>) or Rcdata type (e.g.<textarea>) element, it cannot contain the character sequence which may terminate the corresponding element start tag, e.g.</script, or</textarea.
Getting Started
Installation
Requirements
- PHP 8.4 or higher