I would like to get the temperature value from Yahoo’s weather API. I have found a tutorial but in the tutorial he is getting a different value. Could some one help me modify the tutorial that it could get the temp value from Yahoo’s weather RSS feed?
<yweather:condition text="Partly Cloudy" code="30" temp="3"
date="Mon, 09 Apr 2012 3:48 pm EEST" />
RSS feed: http://weather.yahooapis.com/forecastrss?w=566473&u=c
The tutorial I followed: http://css-tricks.com/using-weather-data-to-change-your-websites-apperance-through-php-and-css/
If some one has a better solution for getting the value don’t hesitate to say it. 🙂
This seems pretty straightforward. From the tutorial:
So, just look at the line with the regular expression:
This is actually a bad regular expression because it assumes
textwill always be the first attribute (and that there’ll always be that weird double-space. Here’s a regular expression that will get thetempattribute regardless of where it falls:Substitute that for the regular expression given to
get_match()and you should be good to go.Oh, and lest I be kicked off SO for not saying so: Attempting to parse arbitrary
HTMLXML with regular expressions is the path to madness.