<?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.
asked Mar 13, 2014 at 5:15
user3399717
1851 gold badge1 silver badge5 bronze badges
-
Its non outputting anything.user3399717– user33997172014年03月13日 05:16:02 +00:00Commented Mar 13, 2014 at 5:16
-
do a vardump of $json and see whay you are gettingManquer– Manquer2014年03月13日 05:19:37 +00:00Commented Mar 13, 2014 at 5:19
2 Answers 2
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.
answered Mar 13, 2014 at 5:19
Shankar Narayana Damodaran
68.6k43 gold badges102 silver badges129 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Rikesh
+1 - You can also suggest him to loop around to get all values not just a first one.
Shankar Narayana Damodaran
Thanks Rik , But seems like he needs just the URL .
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;
?>
answered Mar 13, 2014 at 6:13
ujash joshi
3071 silver badge14 bronze badges
Comments
lang-php