I'd like to retrieve html code in a certain tag. I know DomDocument enables to do it. However, If I want to extract the contents without the outer tag, how can it be achieved?
For example,
$html = '<div><span>Hello world!</span><br><p>some other text</p></div>';
$doc = new DOMDocument;
$doc->loadHTML($html);
echo $doc->saveXML($doc->getElementsByTagName('div')->item(0));
this will output,
<div>
<span>Hello world!</span>
<br>
<p>some other text</p>
</div>
I want it without the outer div tag. I tried the node value but it strips all the tags.
$html = '<div><span>Hello world!</span><br><p>some other text</p></div>';
$doc = new DOMDocument;
$doc->loadHTML($html);
$node = $doc->getElementsByTagName('div')->item(0);
echo $node->nodeValue;
Any ideas?