user3399717
user3399717

Reputation: 165

PHP json_decode displaying blank

<?php
$url = "http://api.giphy.com/v1/gifs/search?q=hello&api_key=dc6zaTOxFJmzC";
$content = file_get_contents($url);
$json = json_decode($content);
echo $json->images[0]->fixedheight->url[0];
?>

I've tried everything- even reading it as an array and it doesn't work.

Any help?

So sorry to bother! Thanks again.

Upvotes: 1

Views: 193

Answers (2)

ujash joshi
ujash joshi

Reputation: 307

use this

 <?php
    $url = "http://api.giphy.com/v1/gifs/search?q=hello&api_key=dc6zaTOxFJmzC";
    $content = file_get_contents($url);
    $json = json_decode($content);
    echo "<pre>";
        print_r($json->data[0]->images->fixed_height->url);
    exit;
    ?>

Upvotes: 0

You should access it this way

echo $json->data[0]->images->fixed_height->url;

That is beacause the $data is an array , and it has an object as its first parameter.

Upvotes: 2

Related Questions