Home |
ProfessionalFamily & Friends |
|
Code: PHPHere I'll plonk (possibly) useful bits of code developed for various purposes professionally or personally. PHPMy main PHP project, since mid 2005, is phpSiteFramework (SF) - this site is currently running on SF version 1.67 (2006-08-19). Cambridge Weather PortletThis is the portlet that runs on the home page of this site. Its basically a 'page scraper', getting the last line of data off today's data page from the weather station located at the University of Cambridge Computer Labs, formats it, and outputs it. <?php function cambs_weather()
{
/* this version uses gmdate() so it will work when
hosted on any server (e.g. in the US)
Note: Ive 'cut up' some of the echo statements so they fit on this page..
Note2: you'll probably want to fix this html, classes etc */
$url="http://www.cl.cam.ac.uk/Research/DTG/attarchive";
$url=$url."/cgi-bin/dailyWeather-cgi?";
$url=$url.gmdate("Y_m_d");
$weatherdata = file($url);
$currentweather = split("\t",$weatherdata[count($weatherdata)-1]);
echo "<b>Weather details at ".$currentweather[0];
echo "</b> from <br/>";
echo "<a href=\"http://www.cl.cam.ac.uk/Research/DTG/attarchive/weather/\"";
echo "class=\"offsite\">CU Computer Labs</a><br/><br/>";
echo "Temperature: ".$currentweather[1]."°C<br/>";
echo "Humidity: ".$currentweather[2]."%<br/>";
echo "Wind Dir/Speed: ".$currentweather[6]."/".$currentweather[5];
echo " knots<br/>";
echo "<br/>Today (".gmdate("d F Y").")<br/>Rainfall: ".$currentweather[8];
echo " mm<br/>";
echo "Sun: ".$currentweather[7]." hrs";
echo "<br/><br/>Cambridge Now:<br/>".gmdate("d/m/y H:i",time()+(1*60*60));
}
Related LinksCambridge University Computer Labs (CL) Digital Technology Group at CL, DTG's Cambridge weather pages |