2012-05-01 40 views
0

我試圖使用Tumblrs API,當我訪問的URL API我得到這個下面API獲取價值的tumblr

{ 
    "meta": { 
     "status": 200 
     "msg": "OK", 
    }, 
    "response": { 
     "blog": { 
      "title": "Ex-Sample", 
      "posts": 20, 
      "name": "example", 
      "url": "http://example.tumblr.com/", 
      "updated": 1327794725, 
      "description": "A sample document used to provide examples of the various [and <i>varying</i>] HTML tags Tumblr puts out. Quote, specifically, has a lot of variants.", 
      "ask": false 
     } 
    } 
} 

的URL http://api.tumblr.com/v2/blog/example.tumblr.com/info?api_key=(APIKEY

我試圖讓上面的URL使用了「發佈」號碼。我將如何在PHP中執行此操作,並且僅回顯數字?

回答

1

這看起來像一個JSON字符串,所以......

$msg = '{"meta" etc.....'; 
$data = json_decode($msg); 
echo $data['meta']['response']['blog']['posts']; 

您可以使用

var_dump($data); 

傾倒在格式良好的樹形結構的整個響應。

+0

很容易,我的問題是我如何把網址到這裏的$味精VAR是url http://api.tumblr.com/v2/blog/example.tumblr.com/info?api_key=YXOMnkQFQ4de5PXkEcwQTtN2a54KxJkECt2KEKQhIaMdi0AVK5 –

+0

你你將如何實際獲取這些數據? 'file_get_contents($ url)'是最簡單的,但如果不可用,還有cURL和其他一些選項。 –

+0

你會如何使用file_get_contents($ url)你可以給我一個例子。 –