PHP SimpleXML + Get Attribute

iHatton

New Member
The XML I am reading looks like this:\[code\]<show id="8511"> <name>The Big Bang Theory</name> <link>http://www.tvrage.com/The_Big_Bang_Theory</link> <started>2007-09-24</started> <country>USA</country> <latestepisode> <number>05x23</number> <title>The Launch Acceleration</title> </latestepisode></show>\[/code\]To get (for example) The number of the latest episode, I would do:\[code\]$ep = $xml->latestepisode[0]->number;\[/code\]This works just fine. But what would I do to get the ID from \[code\]<show id="8511">\[/code\] ?I have tried something like:\[code\]$id = $xml->show;$id = $xml->show[0];\[/code\]But none worked.UpdateMy code snippet:\[code\]$url = "http://services.tvrage.com/feeds/episodeinfo.php?show=".$showName;$result = file_get_contents($url);$xml = new SimpleXMLElement($result);//still doesnt work$id = $xml->show->attributes()->id;$ep = $xml->latestepisode[0]->number;echo ($id);\[/code\]Ori. XML:\[code\]http://services.tvrage.com/feeds/episodeinfo.php?show=The.Big.Bang.Theory\[/code\]
 
Back
Top