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

689

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

908

Answer

Solution:

Have you checked out DOMNode::removeChild ?

People are also looking for solutions to the problem: php - Should every code for the Wordpress plgins be included in the functions and hooked with the Wordpress?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.