- Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Works: * Potatoes * Tomatoes * Carrots Problems: string(2) "ul" string(2) "li" * Potatoes TomatoesCarrots
<?php
function do_it($in)
{
$a = new DOMDocument();
$a->loadHTML($in);
$xpath = new DOMXpath($a);
foreach($xpath->query('/html/body//ul') as $node)
_handle_uls($node);
return $a->textContent;
}
function _handle_uls(DOMNode $node)
{
echo 'Works:' . "\n\n";
foreach ($node->childNodes as $subnode)
echo '* ' . trim($subnode->textContent) . "\n";
echo "\n\n\n" . 'Problems:' . "\n\n";
var_dump($node->nodeName);
foreach ($node->childNodes as $subnode)
{
var_dump($subnode->nodeName);
$textNode = $subnode->ownerDocument->createTextNode('* ' . trim($subnode->textContent) . "\n");
$subnode->ownerDocument->importNode($textNode);
$subnode->parentNode->replaceChild($textNode, $subnode);
}
}
$HTML = '<ul><li>Potatoes</li><li>Tomatoes</li><li>Carrots</li></ul>';
echo do_it($HTML);