I'm using Tumblr API trying to get a Title of a blog. The code I have found does not work for me.
$result = json_decode(file_get_contents('http://example.tumblr.com/api/read/json?num=0'));
$print_r($result);
echo $result[1];
I'm trying to echo out Ex-Sample
but it's giving me blank results. What am I doing wrong?
Thank you
Try this. (tested)
$result = str_replace(array('var tumblr_api_read = ', '};'), array('', '}'), file_get_contents('http://example.tumblr.com/api/read/json?num=0'));
$data = json_decode($result);
echo $data->tumblelog->title;
$print_r($result);
^---you do not have a `$print_r` variable, so you're trying to execute a non-existent function.
json_decode also RETURNS the decoded data. You code should be
$json = file_get_contents(...);
$data = json_decode($json);
echo $data['whatever'];