February 23, 2014 | In: Programovanie
php domdocument extract text nodes with original html
Extracting html from domdocument without parsing original node
preserveWhiteSpace = false; $dom->loadHTML($body); // $html = $dom->saveHTML(); // var_dump($html); // create xpath $xpath = new DOMXPath($dom); // read everything from body $query = '/html/body/* | /html/body/text()'; $entries = $xpath->query($query); foreach ($entries as $entry) { var_dump( // parsed value $entry->nodeValue, // node name (b/div/..) $entry->nodeName, // f.e. comment... $entry->nodeType, // get me the original node (text
Comments are closed.