Parsing XML with simplexml_load_string in PHP

0
<Stat Type="Venue">Allianz Stadium</Stat>
<Stat Type="City">Torino</Stat>

The previous nodes belong to my XML file. the only thing I need to solve it's how I generate the exit and only show me Allianz Stadium.

my code is as follows

foreach ($MatchData->Stat as $stat) {
         echo $stat ."\n"; }

at the time of sending the output I printed both

    
asked by Paulo Mayoral 01.08.2018 в 21:47
source

1 answer

1

If you want the first element, which is found in the index 0 of the object, you can do it in several ways:

Casting string

$stat = (string) $MatchData->Stat[0];
echo $stat;

Using the magic method __toString()

$stat = $MatchData->Stat[0]->__toString();
echo $stat;
    
answered by 02.08.2018 / 00:23
source