1. Go to this page and download the library: Download mensbeam/html-dom 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/ */
namespace MensBeam\HTML\DOM;
partial abstract class Node implements \Stringable {
public readonly \DOMNode $innerNode;
// Common namespace constants provided for convenience
public const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
public const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
public const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
public const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
public const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
public const XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/';
// Used with MensBeam\HTML\DOM\ParentNode::walk
public const WALK_ACCEPT = 0x01;
public const WALK_REJECT = 0x02;
public const WALK_SKIP_CHILDREN = 0x04;
public const WALK_STOP = 0x08;
public function getNodePath(): ?string;
}
namespace MensBeam\HTML\DOM;
partial trait ParentNode {
public function walk(
?\Closure $filter = null,
bool $
namespace MensBeam\HTML\DOM;
$d = new Document(<<<HTML
<!DOCTYPE html>
<html>
<body>
<div><!--Ook!-->
<div>
<div>
<!--Eek!-->
</div>
</div>
<!--Ack!--></div>
</body>
</html>
HTML);
$walker = $d->walk(function($n) {
return ($n instanceof Comment) ? Node::WALK_ACCEPT : Node::WALK_REJECT;
});
echo "The following comments were found:\n";
foreach ($walker as $node) {
echo "$node\n";
}
namespace MensBeam\HTML\DOM;
partial class XPathEvaluator {
public function registerXPathFunctions(Document $document, string|array|null $restrict = null): void;
}
namespace MensBeam\HTML\DOM;
$d = new Document('<!DOCTYPE html><html><body><h1>Ook</h1><p class="subtitle1">Eek?</p><p class="subtitle2">Ook?</p></body></html>');
$e = new XPathEvaluator();
// Register PHP functions (no restrictions)
$e->registerXPathFunctions($d);
// Call substr function on classes
$result = $e->evaluate('//*[php:functionString("substr", @class, 0, 8) = "subtitle"]', $d);
echo "Found " . count($result) . " nodes with classes starting with 'subtitle':\n";
foreach ($result as $node) {
echo "$node\n";
}
partial class XPathResult implements \ArrayAccess, \Countable, \Iterator {}
namespace MensBeam\HTML\DOM\Inner;
partial abstract class Document extends \DOMDocument {
public readonly \MensBeam\HTML\DOM\Node $wrapperNode;
public function getWrapperNode(\DOMNode $node): ?\MensBeam\HTML\DOM\Node;
}
html
<h1>Ook!</h1>
<p>Ook, eek? Ooooook. Ook.</p>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.