3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // http://www.webgeekly.com/tutorials/jquery/how-to-make-your-site-multilingual-using-xml-and-jquery/ $xml = ' <?xml version="1.0" encoding="UTF-8"?> <translations> <translation id="id1"> <es>Españo11</es> <en>English1</en> </translation> <translation id="id2"> <es>Españo12</es> <en>English2</en> </translation> <translation id="id3"> <es>Españo13</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 7.0.0 - 7.1.0
Warning: SimpleXMLElement::__construct(): Entity: line 2: parser error : XML declaration allowed only at the start of the document in /in/4vCbh on line 22 Warning: SimpleXMLElement::__construct(): <?xml version="1.0" encoding="UTF-8"?> in /in/4vCbh on line 22 Warning: SimpleXMLElement::__construct(): ^ in /in/4vCbh on line 22 Fatal error: Uncaught Exception: String could not be parsed as XML in /in/4vCbh:22 Stack trace: #0 /in/4vCbh(22): SimpleXMLElement->__construct('\n<?xml version=...') #1 {main} thrown in /in/4vCbh on line 22
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/4vCbh:22 Stack trace: #0 /in/4vCbh(22): SimpleXMLElement->__construct() #1 {main} Entity: line 2: parser error : XML declaration allowed only at the start of the document <?xml version="1.0" encoding="UTF-8"?> ^
Process exited with code 255.
Output for 5.4.27 - 5.4.45, 5.5.11 - 5.6.28
Warning: SimpleXMLElement::__construct(): Entity: line 2: parser error : XML declaration allowed only at the start of the document in /in/4vCbh on line 22 Warning: SimpleXMLElement::__construct(): <?xml version="1.0" encoding="UTF-8"?> in /in/4vCbh on line 22 Warning: SimpleXMLElement::__construct(): ^ in /in/4vCbh on line 22 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/4vCbh:22 Stack trace: #0 /in/4vCbh(22): SimpleXMLElement->__construct('\n<?xml version=...') #1 {main} thrown in /in/4vCbh on line 22
Process exited with code 255.
Output for 5.1.0 - 5.4.26, 5.5.0 - 5.5.10
Warning: SimpleXMLElement::__construct(): Entity: line 2: parser error : XML declaration allowed only at the start of the document in /in/4vCbh on line 22 Warning: SimpleXMLElement::__construct(): <?xml version="1.0" encoding="UTF-8"?> in /in/4vCbh on line 22 Warning: SimpleXMLElement::__construct(): ^ in /in/4vCbh on line 22 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/4vCbh:22 Stack trace: #0 /in/4vCbh(22): SimpleXMLElement->__construct('?<?xml version=...') #1 {main} thrown in /in/4vCbh on line 22
Process exited with code 255.
Output for 5.0.3 - 5.0.5
Warning: Entity: line 2: parser error : XML declaration allowed only at the start of the document in /in/4vCbh on line 22 Warning: <?xml version="1.0" encoding="UTF-8"?> in /in/4vCbh on line 22 Warning: ^ in /in/4vCbh on line 22 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/4vCbh:22 Stack trace: #0 /in/4vCbh(22): SimpleXMLElement->__construct('?<?xml version=...') #1 {main} thrown in /in/4vCbh on line 22
Process exited with code 255.
Output for 5.0.0 - 5.0.2
Warning: Entity: line 2: parser error : XML declaration allowed only at the start of the document in /in/4vCbh on line 22 Warning: <?xml version="1.0" encoding="UTF-8"?> in /in/4vCbh on line 22 Warning: ^ in /in/4vCbh on line 22 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /in/4vCbh:22 Stack trace: #0 {main} thrown in /in/4vCbh on line 22
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/4vCbh on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/4vCbh on line 22