3v4l.org

run code in 300+ PHP versions simultaneously
<?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');
Output for 7.0.0 - 7.0.20, 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.18, 8.3.0 - 8.3.6
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 5.4.27 - 5.4.45, 5.5.11 - 5.5.38, 5.6.0 - 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.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.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.3.11, 4.4.0 - 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

preferences:
205.39 ms | 401 KiB | 397 Q