1. Go to this page and download the library: Download scotteh/php-dom-wrapper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
scotteh / php-dom-wrapper example snippets
$doc = (new Document())->html('<p>first paragraph</p><p>second paragraph</p>');
$doc->find('p')->addClass('text-center');
composer
php
php
use DOMWrap\Document;
$html = '<ul><li>First</li><li>Second</li><li>Third</li></ul>';
$doc = new Document();
$doc->html($html);
$nodes = $doc->find('li');
// Returns '3'
var_dump($nodes->count());
// Append as a child node to each <li>
$nodes->appendWith('<b>!</b>');
// Returns: <html><body><ul><li>First<b>!</b></li><li>Second<b>!</b></li><li>Third<b>!</b></li></ul></body></html>
var_dump($doc->html());
php
$doc = (new Document())->html('<div>The quick brown fox jumps over the lazy dog</div>');
$doc->find('div')->appendWith('<strong> Appended!</strong>');
php
$doc = (new Document())->html('<div>The quick brown fox jumps over the lazy dog</div>');
$doc->create('<strong> Appended!</strong>')->appendTo('div');
php
$doc = (new Document())->html('<div>The quick brown fox jumps over the lazy dog</div>');
$doc->find('div')->prependWith('<strong>Prepended! </strong>');
php
$doc = (new Document())->html('<div>The quick brown fox jumps over the lazy dog</div>');
$doc->create('<strong>Prepended! </strong>')->appendTo('div');