3v4l.org

run code in 300+ PHP versions simultaneously
<?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 ( 'res.wood' => 'Дерево', 'html.coins' => 'Монеты', 'html.community' => 'Сообщество', 'html.help' => 'Помощь', 'html.play' => 'Играть', 'res.water' => 'Вода', 'html.inv' => 'Пригласить<br>друзей', ) ); var_dump($str);
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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.19, 8.3.0 - 8.3.7
<?xml version="1.0"?> <res.wood>&#x414;&#x435;&#x440;&#x435;&#x432;&#x43E;</res.wood> <html.coins> <html.coin>&#x41C;&#x43E;&#x43D;&#x435;&#x442;&#x44B;</html.coin> </html.coins> <html.community>&#x421;&#x43E;&#x43E;&#x431;&#x449;&#x435;&#x441;&#x442;&#x432;&#x43E;</html.community> <html.help>&#x41F;&#x43E;&#x43C;&#x43E;&#x449;&#x44C;</html.help> <html.play>&#x418;&#x433;&#x440;&#x430;&#x442;&#x44C;</html.play> <res.water>&#x412;&#x43E;&#x434;&#x430;</res.water> <html.inv>&#x41F;&#x440;&#x438;&#x433;&#x43B;&#x430;&#x441;&#x438;&#x442;&#x44C;&lt;br&gt;&#x434;&#x440;&#x443;&#x437;&#x435;&#x439;</html.inv> NULL
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/G4Oqh 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/G4Oqh on line 4

preferences:
294.35 ms | 401 KiB | 458 Q