"php: fetch content from a html page using xpath()" Code Answer

5

this xpath expression:

//div[@id='content']/p

result in the wanted node set (five p elements)

edit: now it's clear what is your problem. you need to iterate over the nodelist:

private function gethtmlfromdom($domnodelist){ 
   $domdocument = new domdocument(); 
   foreach ($nodelist as $node) {
      $domdocument->appendchild($domdocument->importnode($node, true)); 
   }
   return $domdocument->savehtml(); 
} 
By Cylian on March 10 2022

Answers related to “php: fetch content from a html page using xpath()”

Only authorized users can answer the Search term. Please sign in first, or register a free account.