All pastes #769196 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-11-11 06:05 UTC
rendered paste body
  function Weather($loc) {
      $s1 = str_replace(" ","+",$loc);
      $s2 = str_replace(",","%2c",$s1);
      $t = file_get_contents("http://mobile.wunderground.com/cgi-bin/findweather/getForecast?brand=mobile&query=$s2");
      preg_match("/\<b\>(.*?), (.*?)\<\/b\>\n/",$t,$loc);
      preg_match("/\<span class=\"nowrap\"\>\<b\>(.*?)\<\/b\>&#176\;C\<\/span\>/",$t,$temp );
      preg_match("/\<tr\>\<td\>Humidity\<\/td\>\n\<td\>\<b\>(.*?)\<\/b\>\<\/td\>\<\/tr\>/",$t,$hum); 
      preg_match("/\<span class=\"nowrap\"\>\<b\>(.*?)\<\/b\>&nbsp;km\/h\<\/span\>/",$t,$wind);
      preg_match_all("/\<td align=\"right\"\>\<img src=(.*?)\<\/td\>\n  \<td align=\"left\"\>\<b\>(.*?)\<\/b\>\<br \/\>\n  (.*?).\n		(.*?)\n  (.*?)&deg; F.\n  \/\n  (.*?)&deg; C./",$t,$nday);
      return "Weather for $loc[1] in $loc[2] Temperature: $temp[1]"."C - Humidity: $hum[1] - Wind: $wind[1]"."KM/h\n[".$nday[2][0]." - ".$nday[6][0]."C - ".$nday[3][0]."] [".$nday[2][1]." - ".$nday[6][1]."C - ".$nday[3][1]."] [".$nday[2][2]." - ".$nday[6][2]."C - ".$nday[3][2]."] [".$nday[2][3]." - ".$nday[6][3]."C - ".$nday[3][3]."] [".$nday[2][4]." - ".$nday[6][4]."C - ".$nday[3][4]."] [".$nday[2][5]." - ".$nday[6][5]."C - ".$nday[3][5]."] [".$nday[2][6]." - ".$nday[6][6]."C - ".$nday[3][6]."]";
  }