建立连接
$Game_ID = $Game_Search->Game[$i]->id;
$Game_Info_URL = 'http://thegamesdb.net/api/GetGame.php?id='.$Game_ID;
$Game_Info_Output = simplexml_load_file($Game_Info_URL);
检索数据示例
$Game_Info_Images = $Game_Info_Output->Game->Images;
关于这个问题,请参阅我想在哪里获得游戏的URL->图像->美术盒A面和B面。我该怎么称呼它?
XML文档(必填字段)
<Data>
<baseImgUrl>http://thegamesdb.net/banners/</baseImgUrl>
<Game>
<Images>
<boxart side="back" width="1518" height="2148" thumb="boxart/thumb/original/back/90-1.jpg">boxart/original/back/90-1.jpg</boxart>
<boxart side="front" width="1530" height="2148" thumb="boxart/thumb/original/front/90-1.jpg">boxart/original/front/90-1.jpg</boxart>
</Images>
</Game>
</Data>
XML文档(必填字段)
<Data>
<baseImgUrl>http://thegamesdb.net/banners/</baseImgUrl>
<Game>
<Images>
<boxart side="back" width="1518" height="2148" thumb="boxart/thumb/original/back/90-1.jpg">boxart/original/back/90-1.jpg</boxart>
<boxart side="front" width="1530" height="2148" thumb="boxart/thumb/original/front/90-1.jpg">boxart/original/front/90-1.jpg</boxart>
</Images>
</Game>
</Data>
要读取side="front"width="1530"。。。简单使用;
boxart["Attribute_Name"]
示例:
Game->Images->boxart[$b]["side"] // Gets the side value front/back
Game->Images->boxart[$b]["width"] // gets the width value
Game->Images->boxart[$b]["height"] // gets the height value
Game->Images->boxart[$b]["thumb"] // gets the thumb value
DomDocument和/或Xpath:
$dom = new DOMDocument();
$dom->load('http://thegamesdb.net/api/GetGame.php?id=90');
$xpath = new DOMXPath($dom);
$baseImgUrl = $xpath->query('//baseImgUrl')->item(0)->nodeValue;
$boxartBackSide = $xpath->query('//Game/Images/boxart[@side="back"]')
->item(0)->nodeValue;
$boxartFrontSide = $xpath->query('//Game/Images/boxart[@side="front"]')
->item(0)->nodeValue;