3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $xml = '<products><product><features><feature>Dimensions:300x1220x12:8</feature><feature>Weight:25kg:853</feature></features></product></products>'; $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadXML($xml); foreach($doc->getElementsByTagName('feature') as $featureNode) { $values = explode(':', $featureNode->textContent); $newNode = $doc->createElement($values[0]); $newNode->appendChild($doc->createTextNode($values[1])); $featureNode->removeChild($featureNode->firstChild); $featureNode->appendChild($newNode); } $doc->formatOutput = true; echo $doc->saveXML();
Output for 5.6.38 - 7.2.11
<?xml version="1.0"?> <products> <product> <features> <feature> <Dimensions>300x1220x12</Dimensions> </feature> <feature> <Weight>25kg</Weight> </feature> </features> </product> </products>