Hey guys. If you are searching for very simple google weather Unofficial api, so here is the code for it.
<?php
//Created by Roman Losev 2011
//http://pilotaz.blogspot.com/
//email: pilotaz@gmail.com
//Thanks for feedback.
$url = "http://www.google.com/ig/api?weather=Vilnius+Lithuania&hl=lt";
ini_set("user_agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0");
ini_set("content_type","text/xml; charset=\"UTF-8\"");
ini_set("accept_charset","utf-8;q=0.7,*;q=0.7");
ini_set("max_execution_time", 0);
ini_set("memory_limit", "1000M");
$xml = simplexml_load_file($url);
$image_size = "80";
$count = 0;
echo '<div id="weather" align="center">';
$img = IMG_URL."me/hero_bg.gif";
echo "<table border='0' width='400' style=\"background: url(".$img.") bottom left repeat-x #FFF; border: 1px solid #EEE; padding: 20px\">";
foreach($xml->weather as $item) {
echo "<tr><td colspan=\"4\" align='center'>Vilniuje šiandien: ".$item->current_conditions->temp_c['data']."° C, ".$item->current_conditions->humidity['data'].", ".$item->current_conditions->wind_condition['data']."</td></tr><tr>";
foreach($item->forecast_conditions as $new) {
echo '<td style="padding: 4px;" align="center"><div class="weatherIcon">';
echo '<img src="http://www.google.com/' . $new->icon['data'] . '"/ width="'.$image_size.'" height="'.$image_size.'" style="border: 1px solid #a1a1a1"><br/>';
echo $new->day_of_week['data'].": ".$new->low['data']." - ".$new->high['data']."° C";
echo '</div>';
echo "</td>";
}
}
echo "</tr></table>";
echo '</div><br>';
?>
All you need is to change address in $url of the code. GL
ReplyDelete