Querying current weather conditions to make it rain or snow on your site.
<div id="bgimgweather">
<?php
$url = 'http://w1.weather.gov/xml/current_obs/KSYR.xml';
$xml = simplexml_load_file($url);
$currentweather = $xml->weather;
//$currentweather = "Light Rain";
?>
</div>
switch (true) {
case stristr( $currentweather, "Thunderstorm" ):
echo '<div class="bgimgrain"></div>';
echo '<div class="bgimgstorm"></div>';
break;
case stristr( $currentweather, "Snow" ):
echo '<div class="bgimgsnow"></div>';
break;
case stristr( $currentweather, "Rain" ):
case stristr( $currentweather, "Drizzle" ):
case stristr( $currentweather, "Hail" ):
case stristr( $currentweather, "Showers" ):
echo '<div class="bgimgrain"></div>';
break;
case stristr( $currentweather, "Fog" ):
case stristr( $currentweather, "Haze" ):
case stristr( $currentweather, "Smoke" ):
echo '<div class="bgimgfog"></div>';
break;
default:
//Do Nothing
break;
}
.bgimgstorm {position: absolute; top: 0; background: url('img/weather/storm.gif') repeat left top; width: 100%; height: 100%; opacity: 0.2;}
.bgimgsnow {background: url('img/weather/snow.gif') repeat left top; width: 100%; height: 100%;}
.bgimgrain {background: url('img/weather/rain.gif') repeat left top; width: 100%; height: 100%;}
.bgimgfog {background: url('img/weather/fog.png') repeat-x left top; width: 100%; height: 100%;}
<?php
$url = 'http://w1.weather.gov/xml/current_obs/KSYR.xml';
$xml = simplexml_load_file($url);
$currentweather = $xml->weather;
//$currentweather = "Light Rain";
switch (true) {
case stristr( $currentweather, "Light" ):
case stristr( $currentweather, "Drizzle" ):
echo '.bgimgfog {opacity: 0.3;} ';
echo '.bgimgrain {opacity: 0.04;} ';
echo '.bgimgsnow {opacity: 0.04;} ';
echo '/*' . $currentweather . '*/';
break;
case stristr( $currentweather, "Heavy" ):
case stristr( $currentweather, "Thunderstorm" ):
echo '.bgimgfog {opacity: 0.9;} ';
echo '.bgimgrain {opacity: 0.1;} ';
echo '.bgimgsnow {opacity: 0.2;} ';
echo '/*' . $currentweather . '*/';
break;
default:
echo '.bgimgfog {opacity: 0.5;} ';
echo '.bgimgrain {opacity: 0.07;} ';
echo '.bgimgsnow {opacity: 0.08;} ';
echo '/* ' . $currentweather . ' */';
break;
}
?>