2012-05-01 44 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)你可以给我一个例子。 –