cowboysdude Posted December 11, 2015 Share Posted December 11, 2015 (edited) This is the json data I have and I'm trying to get the info out of it but for some reason I am having great difficulty doing so.... array(1) { ["query"]=> array(4) { ["count"]=> int(1) ["created"]=> string(20) "2015-12-11T19:32:29Z" ["lang"]=> string(5) "en-US" ["results"]=> array(1) { ["channel"]=> array(13) { ["title"]=> string(27) "Yahoo! Weather - Elmira, NY" ["link"]=> string(106) "http://us.rd.yahoo.com/dailynews/rss/weather/Elmira__NY/*http://weather.yahoo.com/forecast/USNY0463_f.html" ["description"]=> string(29) "Yahoo! Weather for Elmira, NY" ["language"]=> string(5) "en-us" ["lastBuildDate"]=> string(28) "Fri, 11 Dec 2015 1:52 pm EST" ["ttl"]=> string(2) "60" ["location"]=> array(3) { ["city"]=> string(6) "Elmira" ["country"]=> string(13) "United States" ["region"]=> string(2) "NY" } ["units"]=> array(4) { ["distance"]=> string(2) "mi" ["pressure"]=> string(2) "in" ["speed"]=> string(3) "mph" ["temperature"]=> string(1) "F" } ["wind"]=> array(3) { ["chill"]=> string(2) "59" ["direction"]=> string(3) "230" ["speed"]=> string(2) "12" } ["atmosphere"]=> array(4) { ["humidity"]=> string(2) "55" ["pressure"]=> string(4) "29.8" ["rising"]=> string(1) "0" ["visibility"]=> string(2) "10" } ["astronomy"]=> array(2) { ["sunrise"]=> string(7) "7:24 am" ["sunset"]=> string(7) "4:34 pm" } ["image"]=> array(5) { ["title"]=> string(14) "Yahoo! Weather" ["width"]=> string(3) "142" ["height"]=> string(2) "18" ["link"]=> string(24) "http://weather.yahoo.com" ["url"]=> string(58) "http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif" } ["item"]=> array(9) { ["title"]=> string(40) "Conditions for Elmira, NY at 1:52 pm EST" ["lat"]=> string(5) "42.09" ["long"]=> string(6) "-76.81" ["link"]=> string(106) "http://us.rd.yahoo.com/dailynews/rss/weather/Elmira__NY/*http://weather.yahoo.com/forecast/USNY0463_f.html" ["pubDate"]=> string(28) "Fri, 11 Dec 2015 1:52 pm EST" ["condition"]=> array(4) { ["code"]=> string(2) "34" ["date"]=> string(28) "Fri, 11 Dec 2015 1:52 pm EST" ["temp"]=> string(2) "59" ["text"]=> string(4) "Fair" } This is what I have so far but for some reason I cannot seem to get it to work... $BASE_URL = "http://query.yahooapis.com/v1/public/yql"; $yql_query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="elmira, ny")'; $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json"; // Make call with cURL $session = curl_init($yql_query_url); curl_setopt($session, CURLOPT_RETURNTRANSFER,true); $json = curl_exec($session); // Convert JSON to PHP object $phpObj = json_decode($json, true); // foreach($phpObj['data']['weather'] as $item) { echo "<pre>"; var_dump($phpObj); echo "</pre>"; //echo $phpObj->results->channel->image->url; I would like to get the image url and have tried several ways but no go... suggestions? Thanks in advance! John Edited December 11, 2015 by cowboysdude Quote Link to comment https://forums.phpfreaks.com/topic/299706-having-a-brain-cramp/ Share on other sites More sharing options...
Solution mikesta707 Posted December 11, 2015 Solution Share Posted December 11, 2015 You have to index that $phpObj variable like an array, not an object. IE do $phpObj['key'] not $phpObj->key 1 Quote Link to comment https://forums.phpfreaks.com/topic/299706-having-a-brain-cramp/#findComment-1527840 Share on other sites More sharing options...
cowboysdude Posted December 11, 2015 Author Share Posted December 11, 2015 You have to index that $phpObj variable like an array, not an object. IE do $phpObj['key'] not $phpObj->key WINNER! Thank you so much... this is what worked print_r ($phpObj[query][results][channel][image][url]); Thank you sir! Quote Link to comment https://forums.phpfreaks.com/topic/299706-having-a-brain-cramp/#findComment-1527842 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.