3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xml = '<?xml version="1.0" encoding="UTF-8"?> <translations> <translation id="id1"> <es>Español1</es> <en>English1</en> </translation> <translation id="id2"> <es>Español2</es> <en>English2</en> </translation> <translation id="id3"> <es>Español3</es> <en>English13</en> </translation> </translations>'; $xml = new SimpleXMLElement($xml); $xml = $xml->translation; function translate($xml, $id, $lang) { foreach ($xml as $element) { if($element['id'] == $id) { return $element->{$lang}; } } } echo translate($xml, 'id1', 'es'); echo translate($xml, 'id1', 'en'); echo translate($xml, 'id2', 'es'); echo translate($xml, 'id2', 'en'); echo translate($xml, 'id3', 'es'); echo translate($xml, 'id3', 'en');
based on CJuXn
Output for 5.0.0 - 7.1.0
Español1English1Español2English2Español3English13
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/3ccta on line 18
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/3ccta on line 18