smith.james0 Posted December 7, 2013 Share Posted December 7, 2013 I have a problem with the weather forecast from woe today (Saturday 7th) I get tomorrows forecast as 11th Dec? Is anyone else having problems? James [location_city] => Congleton[location_country] => United Kingdom[wind_chill] => 4[wind_direction] => SW[wind_speed] => 12.87[atmosphere_humidity] => 87[atmosphere_visibility] => 9.99[atmosphere_pressure] => 1015.92[atmosphere_rising] => 0[astronomy_sunrise] => 8:09 am[astronomy_sunset] => 3:50 pm[condition_text] => Partly Cloudy[condition_code] => 29[condition_temp] => 7[forecast_day] => Wed[forecast_date] => 11 Dec 2013[forecast_high] => 7[forecast_low] => 3[forcast_text] => Mostly Sunny[weather_css_class] => partly-cloudy[last_build_date] => Sat, 07 Dec 2013 6:19 pm GMT[hour_of_day] => 18[time_css_class] => evening Quote Link to comment https://forums.phpfreaks.com/topic/284611-woeid-help-needed/ Share on other sites More sharing options...
Barand Posted December 7, 2013 Share Posted December 7, 2013 You are getting day as Wednesday and Wednesday's date. What is your code to get tomorrows date? Quote Link to comment https://forums.phpfreaks.com/topic/284611-woeid-help-needed/#findComment-1461600 Share on other sites More sharing options...
smith.james0 Posted December 7, 2013 Author Share Posted December 7, 2013 $doc = new DOMDocument(); $doc->load("http://weather.yahooapis.com/forecastrss?w=$countryId&u=c"); //now I get all elements inside this document with the following name "channel", this is the 'root' $channel = $doc->getElementsByTagName("*"); // Return array $info = array(); //now I go through each item withing $channel foreach($channel as $element) { // Forcast if($element->localName == "forecast") { $info['forecast_day'] = $element->getAttribute("day"); $info['forecast_date'] = $element->getAttribute("date"); $info['forecast_high'] = $element->getAttribute("high"); $info['forecast_low'] = $element->getAttribute("low"); $info['forcast_text'] = $element->getAttribute("text"); } // Check the RSS-feed if you want to extend this } James Quote Link to comment https://forums.phpfreaks.com/topic/284611-woeid-help-needed/#findComment-1461606 Share on other sites More sharing options...
Barand Posted December 7, 2013 Share Posted December 7, 2013 What should $countryId be in "http://weather.yahooapis.com/forecastrss?w=$countryId&u=c" Quote Link to comment https://forums.phpfreaks.com/topic/284611-woeid-help-needed/#findComment-1461607 Share on other sites More sharing options...
smith.james0 Posted December 7, 2013 Author Share Posted December 7, 2013 What should $countryId be in Sorry I forgot to say the $countryId is the woeid for your area ie 44418 is London James Quote Link to comment https://forums.phpfreaks.com/topic/284611-woeid-help-needed/#findComment-1461608 Share on other sites More sharing options...
Barand Posted December 7, 2013 Share Posted December 7, 2013 There are five "forecast" elements. You are overwriting each one so you end up with just the last one. $countryId=16756; $xml = simplexml_load_file("http://weather.yahooapis.com/forecastrss?w=$countryId&u=c"); $xml->registerXPathNamespace("yweather", current($xml->getNamespaces())); echo $xml->channel->title . '<br>'; foreach ($xml->xpath('//yweather:forecast') as $item) { echo "<i>{$item['day']} {$item['date']}</i> — Low:{$item['low']}° High:{$item['high']}°, {$item['text']}<br>"; } /*** OUTPUT *********************************** Yahoo! Weather - Congleton, GB Sat 7 Dec 2013 — Low:6° High:7°, Partly Cloudy Sun 8 Dec 2013 — Low:8° High:11°, Partly Cloudy Mon 9 Dec 2013 — Low:5° High:9°, Partly Cloudy Tue 10 Dec 2013 — Low:4° High:8°, Partly Cloudy Wed 11 Dec 2013 — Low:3° High:7°, Mostly Sunny ***********************************************/ Quote Link to comment https://forums.phpfreaks.com/topic/284611-woeid-help-needed/#findComment-1461612 Share on other sites More sharing options...
smith.james0 Posted December 8, 2013 Author Share Posted December 8, 2013 Thanks for that James Quote Link to comment https://forums.phpfreaks.com/topic/284611-woeid-help-needed/#findComment-1461674 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.