PHP 8.4.1 Released!

DOMNode::contains

(PHP 8 >= 8.3.0)

DOMNode::containsChecks if node contains other node

说明

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

Checks if node contains other node.

参数

other

Node to be checked.

返回值

Returns true if node contains other node, false otherwise.

示例

示例 #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));
?>

以上示例会输出:

bool(true)
添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top