Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/284611-woeid-help-needed/
Share on other sites

$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

Link to comment
https://forums.phpfreaks.com/topic/284611-woeid-help-needed/#findComment-1461606
Share on other sites

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
***********************************************/
Link to comment
https://forums.phpfreaks.com/topic/284611-woeid-help-needed/#findComment-1461612
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.