Hi,
I'm looking to extract some specific information from an XML feed but I am having problems outputting values from similar tags.
Here is the XML:
<game_live>
<stats team="h">
<player name="A Player" g="0"/>
</stats>
<stats team="a">
<player name="B Player" g="0"/>
</stats>
If you look at the XML above the players separated into two teams using separate 'stats' tags.
Using the code below:
<?php
$xmlFileData = file_get_contents("match-10250605.xml");
$xmlData = new SimpleXMLElement($xmlFileData);
foreach($xmlData->stats as $stats1) {
$name = $stats1->player[0]["name"];
echo "Name: ".$name;
}
?>
The output for this ends up being the names from the first player entry from both the stats tags. So in this case "A PlayerB Player".
If I put the echo outside the loop it only displays the second name "B Player".
How can I separate the two names into seperate variables? I have tried putting $xmlData->stats[0] instead of $xmlData->stats but it outputs nothing.
Cheers.