$content = file_get_contents(http://www.domain.com/page.html);
$dom = new DOMDocument();
if (!@$dom->loadHTML($content)) die ("Couldn't load file?");
$title = $dom->getElementById("cssid");
$data['heading'] = $title->nodeValue; // this works fine
我希望能够选择特定ID范围内的所有p
代码。使用Jquery Ii会做类似$('#mycssid p');
如何使用DOMDocument类
执行此操作答案 0 :(得分:2)
$x = new DOMXPath($dom);
$nodelist = $x->query("//*[@id='cssid']//p");