/ Published in: PHP
Grabs Yahoo!'s weather RSS feed for a given zipcode and extracts the current temperature and conditions, and the forecast for the next two days.
Expand |
Embed | Plain Text
$xml = geturl("http://xml.weather.yahoo.com/forecastrss?p=37205"); preg_match_all('/<yweather:condition.*?text="(.*?)".*?code="(.*?)".*?temp="(.*?)".*?date="(.*?)"/mi', $xml, $current); preg_match_all('/<yweather:forecast.*?date="(.*?)".*?low="(.*?)".*?high="(.*?)".*?text="(.*?)".*?code="(.*?)"/mi', $xml, $forecast); // To download every possible Yahoo! weather code (to find out the codes for rain), run... // curl http://us.i1.yimg.com/us.yimg.com/i/us/we/52/[0-50].gif -o weather_#1.gif $rain = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 35, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47); $day0 = $current[3][0]; $day0_text = $current[1][0]; $day1 = $forecast[3][0]; $day1_text = $forecast[4][0]; $day2 = $forecast[3][1]; $day2_text = $forecast[4][1];
Comments
Subscribe to comments
You need to login to post a comment.

T76YLKOI6