私が読んでいる XML は次のようになります。
<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>
(たとえば)最新のエピソードの番号を取得するには、次のようにします。
$ep = $xml->latestepisode[0]->number;
これはうまくいきます。しかし、から ID を取得するにはどうすればよいでしょう<show id="8511">
か。
私は次のようなことを試しました:
$id = $xml->show;
$id = $xml->show[0];
しかし、どれも機能しませんでした。
アップデート
私のコードスニペット:
$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);
オリ。XML:
http://services.tvrage.com/feeds/episodeinfo.php?show=The.Big.Bang.Theory