1. Go to this page and download the library: Download manychois/simdom 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/ */
manychois / simdom example snippets
use Manychois\Simdom\HtmlParser;
$parser = new HtmlParser();
$doc = $parser->parseDocument('<!DOCTYPE html><html><body><p>Hello, world!</p></body></html>');
// $doc is an instance of \Manychois\Simdom\Document
use Manychois\Simdom\Document;
use Manychois\Simdom\Element;
// Create documents
$doc = Document::create();
// Create elements
$div = Element::create('div');
$div->setAttr('class', 'container');
$div->id = 'main-content';
// Access document parts
$html = $doc->documentElement; // The <html> element
$head = $doc->head; // The <head> element
$body = $doc->body; // The <body> element
// Navigate the tree
$element = $body->firstElementChild;
$nextElement = $element->nextElementSibling;
$parent = $element->parent;
// Child node access
foreach ($body->childNodes as $node) {
echo get_class($node) . "\n";
}
// Element-only access
foreach ($body->children as $element) {
echo $element->name . "\n";
}