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

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-05-25T03:11:08Z Indexed on 2010/05/25 3:21 UTC
Read the original article Hit count: 359

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about domdocument