3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xml = <<< EOT <?xml version='1.0' encoding='UTF-8'?> <eveapi version="2"> <currentTime>2013-10-01 18:00:01</currentTime> <result> <rowset name="members" key="characterID" columns="characterID, name"> <row characterID="2234" name="Bob"> <rowset name="roles" key="roleID" columns="roleID,roleName" /> <rowset name="grantableRoles" key="roleID" columns="roleID,roleName" /> <rowset name="rolesAtHQ" key="roleID" columns="roleID,roleName" /> <rowset name="grantableRolesAtHQ" key="roleID" columns="roleID,roleName" /> <rowset name="rolesAtBase" key="roleID" columns="roleID,roleName" /> <rowset name="grantableRolesAtBase" key="roleID" columns="roleID,roleName" /> <rowset name="rolesAtOther" key="roleID" columns="roleID,roleName" /> <rowset name="grantableRolesAtOther" key="roleID" columns="roleID,roleName" /> <rowset name="titles" key="titleID" columns="titleID,titleName"> <row titleID="256" titleName="Tiger" /> </rowset> </row> <row characterID="555" name="John"> <rowset name="roles" key="roleID" columns="roleID,roleName" /> <rowset name="grantableRoles" key="roleID" columns="roleID,roleName" /> <rowset name="rolesAtHQ" key="roleID" columns="roleID,roleName" /> <rowset name="grantableRolesAtHQ" key="roleID" columns="roleID,roleName" /> <rowset name="rolesAtBase" key="roleID" columns="roleID,roleName" /> <rowset name="grantableRolesAtBase" key="roleID" columns="roleID,roleName" /> <rowset name="rolesAtOther" key="roleID" columns="roleID,roleName" /> <rowset name="grantableRolesAtOther" key="roleID" columns="roleID,roleName" /> <rowset name="titles" key="titleID" columns="titleID,titleName"> <row titleID="16" titleName="R &amp; D" /> <row titleID="64" titleName="Miner" /> <row titleID="256" titleName="Tiger" /> <row titleID="16384" titleName="POS Manager" /> </rowset> </row> </rowset> </result> <cachedUntil>2013-10-01 18:57:01</cachedUntil> </eveapi> EOT; $simpleXML = simplexml_load_string($xml); // Load XML string data into the simplexml object parser foreach ($simpleXML->result->rowset->row as $row) { $titles = []; echo $row; $name = $row['name']->__toString(); foreach($row as $attrib){ if($attrib['name']->__toString() === 'titles'){ foreach($attrib as $title){ $titles[] = $title['titleName']->__toString(); } } } echo $name . ' : ' . implode(' - ', $titles) . "<br/>\n"; }
Output for 5.4.0 - 7.1.0
Bob : Tiger<br/> John : R & D - Miner - Tiger - POS Manager<br/>
Output for 4.4.3 - 4.4.9, 5.1.0 - 5.1.1, 5.1.3 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/LL2vN on line 46
Process exited with code 255.
Output for 4.4.2, 5.1.2
Parse error: syntax error, unexpected '[' in /in/LL2vN on line 47
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/LL2vN on line 46
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/LL2vN on line 46
Process exited with code 255.