I am having a syntax issue. The following code prints all of the names from an XML file.
$url = 'http://my-xml-file';
$xml = simplexml_load_file($url);
foreach($xml->PERSON as $PERSON) {
echo '<div>' . $PERSON->NAME . '</div>';
}
The XML file has now changed and only has 1 person with 1 name in it. How can I modify the code above to echo a single name?
Thanks
UPDATE I have simplified it a bit but the basic XML structure looks like this:
<PERSON>
<NAME>Tom</NAME>
</PERSON>
or just
if there is only 1 entry !
Example : http://codepad.org/g6WUggDq
This is using the XML you supplied …. There should be an outer element surrounding your XML like
<document>and a valid header<?xml version='1.0'?>