3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function xml_encode($mixed, $domElement=null, $DOMDocument=null) { if (is_null($DOMDocument)) { $DOMDocument =new DOMDocument; $DOMDocument->formatOutput = true; xml_encode($mixed, $DOMDocument, $DOMDocument); echo $DOMDocument->saveXML(); } else { if (is_array($mixed)) { foreach ($mixed as $index => $mixedElement) { if (is_int($index)) { if ($index === 0) { $node = $domElement; } else { $node = $DOMDocument->createElement($domElement->tagName); $domElement->parentNode->appendChild($node); } } else { $plural = $DOMDocument->createElement($index); $domElement->appendChild($plural); $node = $plural; if (!(rtrim($index, 's') === $index)) { $singular = $DOMDocument->createElement(rtrim($index, 's')); $plural->appendChild($singular); $node = $singular; } } xml_encode($mixedElement, $node, $DOMDocument); } } else { $mixed = is_bool($mixed) ? ($mixed ? 'true' : 'false') : $mixed; $domElement->appendChild($DOMDocument->createTextNode($mixed)); } } } $str = xml_encode( array ( 'cry_shop' => array ( 'packs' => array ( 3 => array ( 'id' => 3, 'minLevel' => 1, 'elements' => array ( 'crystal' => array ( 'count' => 100, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), ), 'inapSystemName' => 'inap1', 'priceCraft' => array ( ), 'priceCrystal' => NULL, 'crystalOffer' => NULL, 'crystalOfferVal' => NULL, 'crystalOfferStartTime' => NULL, 'crystalOfferEndTime' => NULL, 'translationTitle' => NULL, 'translationDescription' => NULL, ), ), 'translationTitle' => NULL, 'translationDescription' => NULL, ), 'gold_shop' => array ( 'packs' => array ( 2 => array ( 'id' => 2, 'minLevel' => 1, 'elements' => array ( 'gold' => array ( 'count' => 500, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), ), 'inapSystemName' => 'inap1', 'priceCraft' => array ( ), 'priceCrystal' => NULL, 'crystalOffer' => NULL, 'crystalOfferVal' => NULL, 'crystalOfferStartTime' => NULL, 'crystalOfferEndTime' => NULL, 'translationTitle' => NULL, 'translationDescription' => NULL, ), ), 'translationTitle' => NULL, 'translationDescription' => NULL, ), 'res_shop' => array ( 'packs' => array ( 1 => array ( 'id' => 1, 'minLevel' => 1, 'elements' => array ( 'wood' => array ( 'count' => 30, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), 'stone' => array ( 'count' => 50, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), ), 'inapSystemName' => NULL, 'priceCraft' => array ( ), 'priceCrystal' => NULL, 'crystalOffer' => NULL, 'crystalOfferVal' => NULL, 'crystalOfferStartTime' => NULL, 'crystalOfferEndTime' => NULL, 'translationTitle' => NULL, 'translationDescription' => NULL, ), ), 'translationTitle' => NULL, 'translationDescription' => NULL, ), 'util_shop' => array ( 'packs' => array ( 4 => array ( 'id' => 4, 'minLevel' => 0, 'elements' => array ( 'dropRequestCounter' => array ( 'count' => 1, 'offer' => NULL, 'probability' => NULL, 'offerVal' => NULL, 'offerStartTime' => NULL, 'offerEndTime' => NULL, ), ), 'inapSystemName' => NULL, 'priceCraft' => array ( ), 'priceCrystal' => 5, 'crystalOffer' => NULL, 'crystalOfferVal' => NULL, 'crystalOfferStartTime' => NULL, 'crystalOfferEndTime' => NULL, 'translationTitle' => NULL, 'translationDescription' => NULL, ), ), 'translationTitle' => NULL, 'translationDescription' => NULL, ), ) ); var_dump($str);
based on G4Oqh
Output for 5.0.0 - 7.2.0
<?xml version="1.0"?> <cry_shop> <packs> <pack/> <pack> <id>3</id> <minLevel>1</minLevel> <elements> <element> <crystal> <count>100</count> <offer></offer> <probability></probability> <offerVal></offerVal> <offerStartTime></offerStartTime> <offerEndTime></offerEndTime> </crystal> </element> </elements> <inapSystemName>inap1</inapSystemName> <priceCraft/> <priceCrystal></priceCrystal> <crystalOffer></crystalOffer> <crystalOfferVal></crystalOfferVal> <crystalOfferStartTime></crystalOfferStartTime> <crystalOfferEndTime></crystalOfferEndTime> <translationTitle></translationTitle> <translationDescription></translationDescription> </pack> </packs> <translationTitle></translationTitle> <translationDescription></translationDescription> </cry_shop> <gold_shop> <packs> <pack/> <pack> <id>2</id> <minLevel>1</minLevel> <elements> <element> <gold> <count>500</count> <offer></offer> <probability></probability> <offerVal></offerVal> <offerStartTime></offerStartTime> <offerEndTime></offerEndTime> </gold> </element> </elements> <inapSystemName>inap1</inapSystemName> <priceCraft/> <priceCrystal></priceCrystal> <crystalOffer></crystalOffer> <crystalOfferVal></crystalOfferVal> <crystalOfferStartTime></crystalOfferStartTime> <crystalOfferEndTime></crystalOfferEndTime> <translationTitle></translationTitle> <translationDescription></translationDescription> </pack> </packs> <translationTitle></translationTitle> <translationDescription></translationDescription> </gold_shop> <res_shop> <packs> <pack/> <pack> <id>1</id> <minLevel>1</minLevel> <elements> <element> <wood> <count>30</count> <offer></offer> <probability></probability> <offerVal></offerVal> <offerStartTime></offerStartTime> <offerEndTime></offerEndTime> </wood> <stone> <count>50</count> <offer></offer> <probability></probability> <offerVal></offerVal> <offerStartTime></offerStartTime> <offerEndTime></offerEndTime> </stone> </element> </elements> <inapSystemName></inapSystemName> <priceCraft/> <priceCrystal></priceCrystal> <crystalOffer></crystalOffer> <crystalOfferVal></crystalOfferVal> <crystalOfferStartTime></crystalOfferStartTime> <crystalOfferEndTime></crystalOfferEndTime> <translationTitle></translationTitle> <translationDescription></translationDescription> </pack> </packs> <translationTitle></translationTitle> <translationDescription></translationDescription> </res_shop> <util_shop> <packs> <pack/> <pack> <id>4</id> <minLevel>0</minLevel> <elements> <element> <dropRequestCounter> <count>1</count> <offer></offer> <probability></probability> <offerVal></offerVal> <offerStartTime></offerStartTime> <offerEndTime></offerEndTime> </dropRequestCounter> </element> </elements> <inapSystemName></inapSystemName> <priceCraft/> <priceCrystal>5</priceCrystal> <crystalOffer></crystalOffer> <crystalOfferVal></crystalOfferVal> <crystalOfferStartTime></crystalOfferStartTime> <crystalOfferEndTime></crystalOfferEndTime> <translationTitle></translationTitle> <translationDescription></translationDescription> </pack> </packs> <translationTitle></translationTitle> <translationDescription></translationDescription> </util_shop> NULL
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/7SBOP on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/7SBOP on line 4