2013-09-24 54 views
0

我開始創建'部族社區統計'項目時出現問題。 我有一個URL與統計的API,我想用一個簡單的HTML DOM分析器在一個數組中顯示。我想這樣的效果:通過簡單的html dom解析器將API解析爲數組

{ 
    "status": "ok", 
    "count": 1, 
    "data": { 
    "1": { 
     "members_count": 100, 
     "description": "Закрытый клан...", 
     "description_html": "<p>Закрытый клан....\n</p>", 
     "created_at": 1293024672, 
     "updated_at": 1375930001, 
     "name": "Wargaming.net", 
     "abbreviation": "WG", 
     "emblems": { 
     "large": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_64x64.png", 
     "small": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_24x24.png", 
     "medium": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_32x32.png", 
     "bw_tank": "http://cw.worldoftanks.ru/media/clans/emblems/clans_1/1/emblem_64x64_tank.png" 
     }, 
     "clan_id": 1, 
     "members": { 
     "196632": { 
      "created_at": 1293126248, 
      "role": "private", 
      "updated_at": 1375930001, 
      "account_id": 196632, 
      "account_name": "Wrobel" 
     }, 
     "18458": { 
      "created_at": 1360836543, 
      "role": "diplomat", 
      "updated_at": 1375930001, 
      "account_id": 18458, 
      "account_name": "alienraven" 
     }, 
     "3100": { .... 
     } 
     }, 
     "motto": "Орлы! Орлицы!", 
     "clan_color": "#e18000", 
     "owner_id": 1277137 
    } 
    } 
} 

我的代碼

include('simple_html_dom.php'); 
$html = file_get_html('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659'); 
...? 

什麼下一步應準備一個數組,其中我想我的網頁上的方式顯示它怎麼辦?有人有義務向我解釋嗎?請。

問候瑪麗

+0

json_encode /解碼? –

回答

-1

我看到數據是JSON格式。只需使用:

$json = file_get_contents('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659'); //gets the json 
$obj = json_decode($json); //decode the json into object or array. You'll get an object 
var_dump($obj); //view the object. Parse the object the way you want to. 
-1

試試這個

<?php 
// example of how to modify HTML contents 
include('../simple_html_dom.php'); 

// get DOM from URL or file 
$html = file_get_html('http://api.worldoftanks.eu/2.0/clan/info/?application_id=d0a293dc77667c9328783d489c8cef73&clan_id=500009659'); 

$data = json_decode($html); 

echo "<pre>"; 
print_r($data); 
?>