My Google Weather API
I made a weather forecast from google api , Can’t seem to use yahoo weather api so i used this one pretty easy to use…
CSS :
.weatherIcon {
width :58px;
float:left;
}
.box_weather
{
font-size: 28px;color : #fff; background : #4F74A0;width : 50px;float:left; text-align: center;
}
.box_weather_title {
width : 250px;border-bottom : 1px solid #ccc;font-weight: bold;font-size: 20px;margin-left:10px;float:left;
}
PHP
function getWeather() {
$requestAddress = “http://www.google.com/ig/api?weather=medan&hl=id”;
// Downloads weather data based on location - I used my zip code.
$xml_str = file_get_contents($requestAddress,0);
// Parses XML
$xml = new SimplexmlElement($xml_str);
?>
weather->current_conditions->temp_c[‘data’];?>°
Medan
° C
<?
// Loops XML
$count = 0;
echo ‘
’;
foreach($xml->weather as $item) {
foreach($item->forecast_conditions as $new) {
echo ‘
’;
echo $new->day_of_week[‘data’];
echo ‘ icon[‘data’] . ‘”/>
’;
echo $new->low[‘data’].’ | ‘.$new->high[‘data’];
echo ‘
’;
}
}
echo ‘
’;
}
getWeather();
?>