PHP 8.4.0 RC3 available for testing

DOMNode::contains

(PHP 8 >= 8.3.0)

DOMNode::containsVérifie si un nœud contient un autre nœud

Description

public DOMNode::contains(DOMNode|DOMNameSpaceNode|null $other): bool

Vérifie si le nœud contient l'autre nœud other.

Liste de paramètres

other

Le nœud à vérifier.

Valeurs de retour

Renvoie true si le nœud contient le nœud other, sinon false.

Exemples

Exemple #1 Exemple de DOMNode::contains()

<?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));
?>

L'exemple ci-dessus va afficher :

bool(true)
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top