Hi,
I am trying to pull some information from an xml file but I am having trouble trying to access some values. There are two <stats> sections but I can only seem to access the second one.
Here is the XML file:
<game_live>
<stats team="h">
<player name="A Player" shortname="a" num="10" id="250365" pos="INT" k="8" h="10" m="7" t="4" ho="0" ff="2" fa="1" g="0" b="0" in50="2" rankingpoints="87" fantasypoints="80"/>
</stats>
<stats team="a">
<player name="B Player" shortname="b" num="44" id="220009" pos="CHB" k="14" h="12" m="6" t="1" ho="0" ff="0" fa="1" g="0" b="0" in50="1" rankingpoints="92" fantasypoints="85"/>
</stats>
I am trying to get the players name under the first stats section. This would be 'A Player' but I cannot work out how to get it. Below is the code I've used .
<?php
$xmlFileData = file_get_contents("match-10250605.xml");
$xmlData = new SimpleXMLElement($xmlFileData);
foreach($xmlData->stats[0] as $stats1) {
$name = $stats1->player[0]["name"];
}
echo "Name: ".$name;
?>
For some reason there is no output. If I put in just 'stats' instead of 'stats[0]' then it goes straight the second stats section and outputs that players name 'B Player'.
What am I doing wrong?