- simplexml_load_string: documentation ( source)
- implode: documentation ( source)
<?php
$xml = <<< EOT
<?xml version='1.0' encoding='UTF-8'?>
<rowset name="keys" key="keyID" columns="keyID,vCode">
<row keyID="3169149" vCode="FQVKg5iK2k5gnMnafK6fn0K3QUKnWzjRoSv5C2TpgEtC8qFqH9Ism2E4IcFOPkgR" />
<row keyID="3184662" vCode="u7G74sPhQgKz7AqYclI40xlHWqbc7b8bZzPYDC0B4tPXnvNLHu8XbbGyert1YLMs" />
</rowset>
EOT;
$simpleXML = simplexml_load_string($xml); // Load XML string data into the simplexml object parser
foreach ($simpleXML->result->rowset->row as $row) {
$titles = [];
$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";
}