I want to get a list of top-level children nodes from an HTML string. Using PHP's DomDocument, I tried the following:
$html = new DomDocument();
$html->loadHTML('<p>One</p><p>Two</p><p>Three</p>');
foreach( $html->childNodes as $node ) {
echo $node->nodeName . ':' . $node->nodeValue. '<br>';
}
Unfortunately, the output I get is
html:
html:OneTwoThree
Where what I want is something like
paragraph: One
paragraph: Two
paragraph: Three
Am I missing something? PHP documentation isn't of much help. I tried on PHPTester using different PHP versions and still get the same result.