DOMNode::contains

Checks if node contains other node

Description

public bool DOMNode::contains(DOMNodeDOMNameSpaceNodenull $other)

Checks if node contains other node.

Parameters

other

Node to be checked.

Return Values

Returns true if node contains other node, false otherwise.

Examples

Example #1 DOMNode::contains example

<?php

$dom = new DOMDocument();
$dom->loadXML(<<<XML
<!DOCTYPE HTML>
<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:

bool(true)