I'm trying to use Tumblr API I believe its JSON. I'm trying to get the "posts-total" in the URL below using Php and echo it out. How would I do this?
http://example.tumblr.com/api/read/json?num=0
Thank you
Update:
I trying to use
$result = json_decode(file_get_contents('http://example.tumblr.com/api/read/json?num=0'));
$print_r($result);
echo $result[1];
I'm getting a 500 error. When I just try to echo out $result I get nothing.
Simple php-
$result = json_decode(file_get_contents('http://example.tumblr.com/api/read/json?num=0'));
print_r($result); //will show contents return in an araay format
echo $result[1]; //or whatever the element is
I was having a similar issue and think I worked it out.
var tumblr_api_read = {"tumblelog":{"title":"Ex-Sample","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.","name":"example","timezone":"US\/Eastern","cname":false,"feeds":[]},"posts-start":0,"posts-total":"20","posts-type":false,"posts":[]};
It appears that the json being sent back favors javascript and is not pure json. Thus the json_decode function is having a problem trying to parse it. It appears that you can add a debug=1 argument to the url and receive a json string that PHP can handle.
$result = json_decode(file_get_contents('http://example.tumblr.com/api/read/json?num=0&debug=1'));
$print_r($result);
echo $result[1];