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 div. How can I change this code to output the div's HTML content and not plain text, AND also output the main div wrapping it's child elements.

Example:

contents of file.txt:

<div class="1"><span class="test">text text text</span></div>
<div class="2"><span class="test">text text text</span></div>
<div class="3"><span class="test">text text text</span></div>

script.php:

  $file= file_get_contents('file.txt');

    $doc = new DOMDocument();

    @$doc->loadHTML('<?xml encoding="UTF-8">'.$file); 

    $entries = $doc->getElementsByTagName('div');

        for ($i=0;$i<$entries->length;$i++) {
            $entry = $entries->item($i);
            echo $entry->nodeValue;
        }

outputs: text text texttext text texttext text text

what I need it to output:

<div class="1"><span class="test">text text text</span></div>
<div class="2"><span class="test">text text text</span></div>
<div class="3"><span class="test">text text text</span></div>

Notice the parent div's (..etc) are needed to be outputted as well wrapping the span tags...

HELP!

Edit
Report