-1

I am using the following code to get the first of a page. However I can not get it. What am I missing here ?

$doc = new DOMDocument();
$doc->loadhtmlfile("");
$xpath = new DOMXpath($doc);

$descr = $xpath->query('//div[@class="description"]');
    print_r($descr);
4

1 回答 1

1

query()返回一个 DOMNodeList,要获取<div>DOMNode,需要从列表中获取:

$descr = $xpath->query('//div[@class="description"]')->item(0);

现在,$descr包含第一个<div>带有 class的 DOMNode description

于 2012-07-31T14:13:45.110 回答