I'll post the version with all my comments and ramblings (I think it's the same one):
Also help for the last rain time data file
<?php
// Based on anchorageweather's (www.eetee.us/station) precision-time
// "DaysWithouRain" script.
//
// Modified for basic "days since last rain" usage.
// "Days since" increment based on midnite.
//
// Added WeatherLink rain rate tag usage for text output.
// during different levels of rain "Cats & dogs",etc.
// Requires an WL upload interval of one minute to be fun.
// Also used for "It rained today!" display.
//
// For first time usage: find last day it rained and convert
// it to a Unix timestamp. (www.onlineconversion.com/unix_time.htm)
// Save that value to a file called "lastrainday.txt"
// WeatherLink runs the htx file and saves to php.
$myFile = "./scripts/lastrainday.txt";
$fh = fopen($myFile, 'r');
$lastrainday = fread($fh, 20);
fclose($fh);
$now = mktime();
$dailyrain = <!--dailyRain-->;
$rainrate = <!--rainRate-->;
// Get current date and time but reset time to 1 second after midnite
// as will be found in lastrainday.txt
$newstarttime = mktime(0,0,1);
// Save today's start time to text file ONLY if it rained
// AND if $lastrainday is older than today's $newstarttime
// Avoids rewriting file unless a new day AND rained
if (($lastrainday < $newstarttime) and ($dailyrain > 0))
{
$runningseconds = 0;
$myFile = "./scripts/lastrainday.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$newrainday = $newstarttime;
fwrite($fh, $newrainday);
fclose($fh);
}
else
{
$runningseconds = ($now - $lastrainday);
}
$runningdays = floor(($runningseconds/86399));
// I wanted to see the Davis console's "IT'S RAINING CATS & DOGS!" on my site.
// The rain rate values used here were acquired by using the tried and true
// scientific method of standing outside... in the rain... like an idiot...
// Change the values or the responses to suit.
if ($rainrate > 0 && $rainrate< .07) echo "THERE'S A SOFT RAIN FALLING";
elseif ($rainrate >= .07 && $rainrate <.75) echo "IT'S RAINING RIGHT NOW!";
elseif ($rainrate >= .75 && $rainrate <1.75) echo "IT'S RAINING HARD RIGHT NOW!";
elseif ($rainrate >= 1.75 && $rainrate <2.50) echo "IT'S RAINING CATS & DOGS!";
elseif ($rainrate >= 2.50 && $rainrate <4.50) echo "IT'S POURING BUCKETS OF RAIN!!!";
elseif ($rainrate >= 4.50) echo "QUICK!!! SOMEBODY BUILD AN ARK!";
elseif ($dailyrain > 0) echo "IT RAINED TODAY!";
// Prevents the silly looking "1 dayS..." response and displays month and day of last rain
elseif ($runningdays == 1)
{echo $runningdays." day since rain was last recorded: ".date('M d',$lastrainday);}
// Optional...
// {echo "IT RAINED YESTERDAY";
else
{echo $runningdays." days since rain was last recorded: ".date('M d',$lastrainday);}
// I hope others enjoy it! - Cienega32 - www.EastMesaWeather.com
?>