json - How to echo the cURL result in PHP? -
here url→ https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=snoopy&rsz=1
and php code
<?php $url = "https://ajax.googleapis.com/ajax/services/search/images?"."v=1.0&q=snoopy"; $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_returntransfer, 1); $body = curl_exec($ch); curl_close($ch); $json = json_decode($body); ?>
i wanna echo of image urls result
(for example: http://img2.wikia.nocookie.net/__cb20110331075248/peanuts/images/6/62/snoopy.gif )
but have no idea how echo them.
hope me, thanks!
in order echo exact result use:
echo $body; //echoes json string
if want echo exact link, echo this:
echo $json->responsedata->results[0]->url; //echoes http://img2.wikia.nocookie.net/__cb20110331075248/peanuts/images/6/62/snoopy.gif
or can foreach()
twice (or once...) echo $res->url
directly :) choise!
Comments
Post a Comment