3v4l.org

run code in 500+ PHP versions simultaneously
<?php $filedata = <<<EOT <?xml version="1.0" encoding="utf-8" ?> <article xmlns="http://docbook.org/ns/docbook" version="5.0" xmlns:xlink="http://www.w3.org/1999/xlink" > <para> This is an <emphasis role="strong">hello <em>world</em></emphasis> sentence. </para> </article> EOT; $dom = new DOMDocument(); $dom->loadXML($filedata); foreach($dom->documentElement->childNodes as $node){ if(XML_ELEMENT_NODE === $node->nodeType && 'para' === $node->nodeName){ // Replace any emphasis elements foreach($node->childNodes as $childNode) { if(XML_ELEMENT_NODE === $childNode->nodeType && 'emphasis' === $childNode->nodeName){ // This is arguably the most "correct" way to replace, just in case // there's extra nodes inside. A cheaper way would be to not loop // and just use the nodeValue however you might lose some HTML. $newNode = $dom->createElement('b'); foreach($childNode->childNodes as $grandChild){ $newNode->appendChild($grandChild->cloneNode(true)); } $childNode->replaceWith($newNode); } } // Build our output $output = ''; foreach($node->childNodes as $childNode) { $output .= $dom->saveHTML($childNode); } // The provided XML has a namespace, and when cloning nodes that NS comes // along. Since we are going from regular XML to irregular HTML I think // a string replacement is best. $output = str_replace(' xmlns="http://docbook.org/ns/docbook"', '', $output); echo $output; } }
Output for rfc.property-hooks, git.master, git.master_jit
This is an <b>hello <em>world</em></b> sentence.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
35.06 ms | 1258 KiB | 4 Q