开发者

Can I get the matched DOM string with PHP and DOMDocument?

开发者 https://www.devze.com 2022-12-31 17:48 出处:网络
I\'ve got my HTML inside of $html. dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom);

I've got my HTML inside of $html.

dom = new DOMDocument();
$dom->loadHTML($html);


$xpath = new DOMXPath($dom);

$tags = $xpath->query('//div[@id="header"]');


foreach($tags as $tag) 开发者_如何转开发{

    var_dump($tag->nodeValue); // the innerHTML of that element
    var_dump($tag); // object(DOMElement)#3 (0) { }

}

Is there a way to get that node, or remove it?

Basically, I'm parsing an existing website and need to remove elements from it. What method do I call to do that?

Thanks


Have you checked out DOMNode::removeChild ?

0

精彩评论

暂无评论...
验证码 换一张
取 消