3v4l.org

run code in 300+ PHP versions simultaneously
<?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); 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);
Output for 8.3.0 - 8.3.6
Works: * Potatoes * Tomatoes * Carrots Problems: object(DOMElement)#3 (27) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(2) "ul" ["className"]=> string(0) "" ["id"]=> string(0) "" ["firstElementChild"]=> string(22) "(object value omitted)" ["lastElementChild"]=> string(22) "(object value omitted)" ["childElementCount"]=> int(3) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> NULL ["nodeName"]=> string(2) "ul" ["nodeValue"]=> string(23) "PotatoesTomatoesCarrots" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["parentElement"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> NULL ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["isConnected"]=> bool(true) ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(2) "ul" ["baseURI"]=> NULL ["textContent"]=> string(23) "PotatoesTomatoesCarrots" } string(2) "li" * Potatoes TomatoesCarrots
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Works: * Potatoes * Tomatoes * Carrots Problems: object(DOMElement)#3 (23) { ["schemaTypeInfo"]=> NULL ["tagName"]=> string(2) "ul" ["firstElementChild"]=> string(22) "(object value omitted)" ["lastElementChild"]=> string(22) "(object value omitted)" ["childElementCount"]=> int(3) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> NULL ["nodeName"]=> string(2) "ul" ["nodeValue"]=> string(23) "PotatoesTomatoesCarrots" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> NULL ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(2) "ul" ["baseURI"]=> NULL ["textContent"]=> string(23) "PotatoesTomatoesCarrots" } string(2) "li" * Potatoes TomatoesCarrots
Output for 8.0.0 - 8.0.30
Works: * Potatoes * Tomatoes * Carrots Problems: object(DOMElement)#3 (23) { ["tagName"]=> string(2) "ul" ["schemaTypeInfo"]=> NULL ["firstElementChild"]=> string(22) "(object value omitted)" ["lastElementChild"]=> string(22) "(object value omitted)" ["childElementCount"]=> int(3) ["previousElementSibling"]=> NULL ["nextElementSibling"]=> NULL ["nodeName"]=> string(2) "ul" ["nodeValue"]=> string(23) "PotatoesTomatoesCarrots" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> NULL ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(2) "ul" ["baseURI"]=> NULL ["textContent"]=> string(23) "PotatoesTomatoesCarrots" } string(2) "li" * Potatoes TomatoesCarrots
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Works: * Potatoes * Tomatoes * Carrots Problems: object(DOMElement)#3 (18) { ["tagName"]=> string(2) "ul" ["schemaTypeInfo"]=> NULL ["nodeName"]=> string(2) "ul" ["nodeValue"]=> string(23) "PotatoesTomatoesCarrots" ["nodeType"]=> int(1) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> NULL ["nextSibling"]=> NULL ["attributes"]=> string(22) "(object value omitted)" ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(2) "ul" ["baseURI"]=> NULL ["textContent"]=> string(23) "PotatoesTomatoesCarrots" } string(2) "li" * Potatoes TomatoesCarrots

preferences:
172.3 ms | 404 KiB | 183 Q