且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从DOMNodeList获取原始

更新时间:2023-01-22 20:08:28

DOMNodeList :: item() 将在其中提供 DOMNode DOMNodeList 按索引。例如,要获取列表中的第一个节点:

DOMNodeList::item() will give a DOMNode in the DOMNodeList by index. For example, to get the first node in the list:

$dom->getElementsByTagName('url')->item(0)

要获取元素包含的实际数据,请使用如下代码: / p>

To get the actual data that the element contains, use code something like this:

if ($node = $dom->getElementsByTagName('url')->item(0)) {
  $url = $node->nodeValue;
} else {
  // Element does not exist, handle error here
}