DOMNode::contains
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.3.0)
Checks if node contains other node
Description
DOMNode::contains(DOMNode|DOMNameSpaceNode|null $other): bool
Checks if node contains other node.
Parameters
otherNode to be checked.
Return Values
Returns true if node contains other node, false otherwise.
Examples
DOMNode::contains example
php
<?php
$dom = new DOMDocument();
$dom->loadXML(<<<XML
<html>
<body>
<main>
<p>Hello, world!</p>
</main>
</body>
</html>
XML);
$xpath = new DOMXPath($dom);
$main = $xpath->query("//main")[0];
var_dump($dom->documentElement->contains($main));
?>The above example will output:
output
bool(true)