3v4l.org

run code in 200+ PHP versions simultaneously
<?php $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <root> <item> <foo id=\"1\"><![CDATA[123]]></foo> <bar><![CDATA[abc]]></bar> </item> <item> <foo id=\"1\">123</foo> <bar>abc</bar> </item> </root>"; $sxml = simplexml_load_string($xml, null, LIBXML_NOCDATA); print_r($sxml); print_r($sxml->item[0]->foo["id"]);
Output for 7.1.0 - 7.4.0
SimpleXMLElement Object ( [item] => Array ( [0] => SimpleXMLElement Object ( [foo] => 123 [bar] => abc ) [1] => SimpleXMLElement Object ( [foo] => 123 [bar] => abc ) ) ) SimpleXMLElement Object ( [0] => 1 )