PHPackages                             phpgt/dom - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpgt/dom

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpgt/dom
=========

Modern DOM API.

v4.1.9(2mo ago)12412.2M—5.5%27[2 issues](https://github.com/PhpGt/Dom/issues)[1 PRs](https://github.com/PhpGt/Dom/pulls)16MITPHPPHP &gt;=8.1CI passing

Since Feb 3Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/PhpGt/Dom)[ Packagist](https://packagist.org/packages/phpgt/dom)[ GitHub Sponsors](https://github.com/sponsors/PhpGt)[ RSS](/packages/phpgt-dom/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (65)Used By (16)

[![The modern DOM API for PHP 7 projects](logo.png)](logo.png)

Modern DOM API.
===============

[](#modern-dom-api)

Built on top of PHP's native [DOMDocument](http://php.net/manual/en/book.dom.php), this project provides access to modern DOM APIs, as you would expect working with client-side code in the browser.

Performing DOM manipulation in your server-side code enhances the way dynamic pages can be built. Utilising a standardised object-oriented interface means the page can be ready-processed, benefiting browsers, webservers and content delivery networks.

---

[ ![Build status](https://camo.githubusercontent.com/acd3b433af5a7bdfafc66e093771f715091b9bb5507fc94747d22e367b91b99f/68747470733a2f2f62616467652e7374617475732e7068702e67742f646f6d2d6275696c642e737667)](https://github.com/PhpGt/Dom/actions)[ ![Code quality](https://camo.githubusercontent.com/98f19628a9533af724fde5bcf95a43cb3f1b2645beac5c368adaac73d5441df3/68747470733a2f2f62616467652e7374617475732e7068702e67742f646f6d2d7175616c6974792e737667)](https://app.codacy.com/gh/PhpGt/Dom)[ ![Code coverage](https://camo.githubusercontent.com/a6e33699401ff359416e9dd7b5a6bd4081b065c76b45c419b3bf3c0479d775d1/68747470733a2f2f62616467652e7374617475732e7068702e67742f646f6d2d636f7665726167652e737667)](https://app.codecov.io/gh/PhpGt/Dom)[ ![Current version](https://camo.githubusercontent.com/e7869dcc279dd8f67154f6f90ff34f5be0d46dea814ff8a34f243d17d0e6386d/68747470733a2f2f62616467652e7374617475732e7068702e67742f646f6d2d76657273696f6e2e737667)](https://packagist.org/packages/PhpGt/Dom)[ ![PHP.Gt/Dom documentation](https://camo.githubusercontent.com/08fef26351638a63f0357d4382c10c68ca33b4b8fa191285fcf98ca359f5d077/68747470733a2f2f62616467652e7374617475732e7068702e67742f646f6d2d646f63732e737667)](https://www.php.gt/dom)Example usage: Hello, you!
--------------------------

[](#example-usage-hello-you)

> **Important note:** the example shown here is for illustrative purposes, but using the DOM to directly set data to elements' values tightly couples the logic to the view, which is considered bad practice. Please see the [DomTemplate](https://php.gt/domtemplate) library for a more robust solution to binding data to the DOM.

Consider a page with a form, with an input element to enter your name. When the form is submitted, the page should greet you by your name.

This is a simple example of how source HTML files can be treated as templates. This can easily be applied to more advanced template pages to provide dynamic content, without requiring non-standard techniques such as `{{curly braces}}` for placeholders, or `echo '' . $content['opa'] . ''` error-prone HTML construction from within PHP.

### Source HTML (`name.html`)

[](#source-html-namehtml)

```

	Hello, you !

	Submit

```

### PHP used to inject your name (`index.php`)

[](#php-used-to-inject-your-name-indexphp)

```
