I am trying to get the innerhtml of div tags in a file using nodeValue, however this code is outputting only plain text and seems to strip out all html tag from inside the d
Instead of:
echo $entry->nodeValue;
You have to use:
echo $doc->saveXML($entry);
Here is a more complete example that might help others too, $doccontent is the HTML block as a string:
$doccontent = ' …'; // your html string
$dom = new DOMDocument;
$internalErrors = libxml_use_internal_errors(true); // prevent error messages
$content_utf = mb_convert_encoding($doccontent, 'HTML-ENTITIES', 'UTF-8'); // correct parsing of utf-8 chars
$dom->loadHTML($content_utf);
libxml_use_internal_errors($internalErrors); // prevent error messages
$specialdiv = $dom->getElementById('xdiv');
if(isset($specialdiv))
{
echo $dom->saveXML($specialdiv);
}