<?php
outputImages();
outputSpans();
function outputImages(){
$html = "<div class='test'>
<pre>
<img src='http://d...content-available-to-author-only...e.com/5x5/000/fff'>
<img src='http://d...content-available-to-author-only...e.com/5x5/000/fff'>
<img src='http://d...content-available-to-author-only...e.com/5x5/000/fff'>
</pre>
</div>";
getHtml($html);
}
function outputSpans(){
$html = "<div class='test'>
<pre>
<span>a</span>
<span>b</span>
<span>c</span>
</pre>
</div>";
getHtml($html);
}
function getHtml($html){
$doc = new DOMDocument;
$doc->loadhtml($html);
$xpath = new DOMXPath($doc);
$tags = $xpath->query('//div[@class="test"]');
print(get_inner_html($tags[0]));
}
function get_inner_html( $node ) {
$innerHTML= '';
$children = $node->childNodes;
foreach ($children as $child) {
$innerHTML .= $child->ownerDocument->saveXML( $child );
}
return $innerHTML;
}
PD9waHAKCW91dHB1dEltYWdlcygpOwoJb3V0cHV0U3BhbnMoKTsKCQoJCgkKCQoJZnVuY3Rpb24gb3V0cHV0SW1hZ2VzKCl7CgkJJGh0bWwgPSAiPGRpdiBjbGFzcz0ndGVzdCc+CgkJCQkJPHByZT4KCQkJCQk8aW1nIHNyYz0naHR0cDovL2QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmUuY29tLzV4NS8wMDAvZmZmJz4KCQkJCQk8aW1nIHNyYz0naHR0cDovL2QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmUuY29tLzV4NS8wMDAvZmZmJz4KCQkJCQk8aW1nIHNyYz0naHR0cDovL2QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmUuY29tLzV4NS8wMDAvZmZmJz4KCQkJCQk8L3ByZT4KCQkJCTwvZGl2PiI7CgkJZ2V0SHRtbCgkaHRtbCk7Cgl9CgoJCglmdW5jdGlvbiBvdXRwdXRTcGFucygpewoJCSRodG1sID0gIjxkaXYgY2xhc3M9J3Rlc3QnPgoJCQkJCTxwcmU+CgkJCQkJPHNwYW4+YTwvc3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