To make it more "universal"....
So if anyone wants to use this script - or you as well...
Create your custom-styled HTML page, where you can do whatever you want with colors, layout etc. Put some arbitrary fixed values for the actual calculated values, just to be able to make some nice design, that fits your needs, plus text etc.
When you are done, place this code at the beginning of the page - i.e. before the <html> tag:
<?php
// GET TODAY'S DATA
$myfile = fopen("realtime.txt", "r") or die("Unable to open file!");
$current = fread($myfile,filesize("realtime.txt"));
$current_split = array();
$current_split = explode(" ",$current);
$max_today = $current_split[26];
$min_today = $current_split[28];
fclose($myfile);
// LOAD CSV
$history = array();
$file = fopen("dayfile.csv","r");
while(! feof($file))
{
array_push($history,(fgetcsv($file)));
}
fclose($file);
// COMPARE AND LOOP THROUGH HISTORY
for($i=(count($history)-2);$i>0;$i--){
$temporary_min = $history[$i][4];
if($last_min==""){
if($temporary_min<$min_today){
$last_min = $history[$i][4];
$last_min_date = date_create_from_format("d/m/y",$history[$i][0]);
}
}
}
for($i=(count($history)-2);$i>0;$i--){
$temporary_max = $history[$i][6];
if($last_max==""){
if($temporary_max>$max_today){
$last_max = $history[$i][6];
$last_max_date = date_create_from_format("d/m/y",$history[$i][0]);
}
}
}
$current_date = date_create_from_format("d/m/y",date('d/m/y'));
$min_diff = date_diff($current_date,$last_min_date);
$max_diff = date_diff($current_date,$last_max_date);
?>
Then, you can replace the "dummy" values with the real ones - again, you can set font, color etc. just like a regular HTML.
For the following parameters just instead of the fixed number, insert this line of code:
- todays minimum so far - <?php echo $min_today?>
- todays maximum so far - <?php echo $min_today?>
- the date it was last time colder than this - <?php echo $last_min_date?>
- the date it was last time warmer than this - <?php echo $last_max_date?>
- the temperature on that last day when it was colder - <?php echo $last_min?>
- the temperature on that last day when it was colder - <?php echo $last_max?>
Then, if you also wanted the actual time difference between that date and today, for the minimum just write paste this:
<?php
if($min_diff->format("%y")==0 && $min_diff->format("%m")==0){
if($min_diff->format("%d")==1){
echo "yesterday";
}
else{
echo $min_diff->format("%d days ago");
}
}
else if($min_diff->format("%y")==0){
echo $min_diff->format("%m months and %d days ago");
}
else{
echo $min_diff->format("%y years, %m months and %d days ago");
}
?>
for maximum this:
<?php
if($max_diff->format("%y")==0 && $max_diff->format("%m")==0){
if($max_diff->format("%d")==1){
echo "yesterday";
}
else{
echo $max_diff->format("%d days ago");
}
}
else if($max_diff->format("%y")==0){
echo $max_diff->format("%m months and %d days ago");
}
else{
echo $max_diff->format("%y years, %m months and %d days ago");
}
?>
You will get either:
- yesterday
- number of days
- number of days and months (if months is 0, you will only get the number of days obviously)
- alternatively number of years, again, if it isnt zero
Finally - dont forget to save the file, but change the extension from .html to .php!