I can't get on the GRLevelX.com board.
Can someone post the php script that will convert GMT time to local time?!?
Mike mentioned something the other day when we were going through the crisis with the NOAA servers....
He mentioned where the files were located.
http://weather.noaa.gov/pub/SL.us008001/DF.of/DC.radar/DS.p19r0/In those files is a TIMESTAMP! in text.
http://weather.noaa.gov/pub/SL.us008001/DF.of/DC.radar/DS.p19r0/SI.koax/sn.lastHello PHP.
Pull timestamp... reformat to my time... and VOILA! timestamp in local time.
$lastradar = implode('', 'http://weather.noaa.gov/pub/SL.us008001/DF.of/DC.radar/DS.p19r0/SI.koax/sn.last');
$slice = explode("KOAX ",$lastradar);
$slice = explode("N0ROAX",$slice[1]);
$lastradar=$slice[0];
$days=substr($lastradar, 0, 2);
$hours=substr($lastradar, 2, 2);
$minutes=substr($lastradar, 4, 2);
$lastradarUTC = mktime($hours, $minutes, 0, $days);
putenv('TZ=US/Central');
$lastradartime = date("g:i A", $lastradarUTC);
echo $lastradartime;
I have it functioning in test on my current radar image.
Then Jeff an MichiganWxSystem.com posted...
tested on php 5.2 .. and according to the php website will work on
all versions of php 5
<?
$radar = "kapx";
$tz = "-5";
$fp = fopen("http://weather.noaa.gov/pub/SL.us008001/DF.of/DC.radar/DS.p19r0/SI.".$radar."/sn.last", "r");
$data =stream_get_contents($fp);
if (preg_match('/(\d\d)(\d\d)(\d\d)/' , $data , $mm)){
$vd = $mm[1]; $vh = $mm[2]; $vm = $mm[3];}
////////// GMT TO EPOCH CONVERSION
$m = gmdate('m');
$d= gmdate('d');
$y= gmdate('y');
if ($vd < $d) {
$m++;
if ($m > 12) {
$m=1;
$y++;
}
}
$radarepoch = gmmktime($vh,$vm,0,$m,$vd,$y);
$timestamp = gmdate('m/d/Y g:i A' , $radarepoch+$tz*3600);
echo $timestamp
?>
results
http://www.michiganwxsystem.com/test/time.phpAnd he posted...
php 4 version ....
(actually this will work on php 4.4.4 and above to the current of php 5.2.0)
<?
$radar = "kapx";
$tz = "-5";
$vd='';$vh='';$vm='';$data='';
$url = "http://weather.noaa.gov/pub/SL.us008001/DF.of/DC.radar/DS.p19r0/SI.".$radar."/sn.last";
$fp = fopen($url, "r");
while (!feof($fp)){
$data .= fread($fp, 8192);}
if (preg_match('/(\d\d)(\d\d)(\d\d)/' , $data , $mm)){
$vd = $mm[1]; $vh = $mm[2]; $vm = $mm[3];}
////////// GMT TO EPOCH CONVERSION
$m = gmdate('m');
$d= gmdate('d');
$y= gmdate('y');
if ($vd < $d) {
$m++;
if ($m > 12) {
$m=1;
$y++;
}
}
$radarepoch = gmmktime($vh,$vm,0,$m,$vd,$y);
$timestamp = gmdate('m/d/Y g:i A' , $radarepoch+$tz*3600);
echo $timestamp
?>
if you wanted to just return time, remove the m/d/y in the $timestamp variable set
And then I posted...
I went ahead and masked the tilt with a rectangle...
$brown = imagecolorallocate($im, 138, 99, 68);
imagefilledrectangle($im, 466, 474, 506, 489, $brown);
And then added the converted time over the rectangle.
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im,$font,468,475,$text,$black);
imagestring($im,$font,467,474,$text,$white);
I did my darnest to match the bitmap font on the radar... it's acceptable.

And finally... here's my current code (which is specific to KOAX... you'd have to change the explodes to be your particular radar site.
<?php
$lastradar = fetchthisUrlWithoutHanging('http://weather.noaa.gov/pub/SL.us008001/DF.of/DC.radar/DS.p19r0/SI.koax/sn.last');
putenv('TZ=US/Central');
$slice = explode("KOAX ",$lastradar);
$slice = explode("N0ROAX",$slice[1]);
$lastradar=$slice[0];
if (strlen($lastradar)>2) {
$vd=substr($lastradar, 0, 2);
$vh=substr($lastradar, 2, 2);
$vm=substr($lastradar, 4, 2);
////////// GMT TO EPOCH CONVERSION
$m = gmdate('m');
$d= gmdate('d');
$y= gmdate('y');
if ($vd < $d) {
$m++;
if ($m > 12) {
$m=1;
$y++;
}
}
$radarepoch = gmmktime($vh,$vm,0,$m,$vd,$y);
$lastradartime = date("g:iA", $radarepoch);
} else {
$current_time = time();
$lastradartime = date("g:iA",$current_time-120);
}
echo $lastradartime;
function fetchthisUrlWithoutHanging($url)
{
// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
$numberOfSeconds=4;
// Suppress error reporting so Web site visitors are unaware if the feed fails
error_reporting(0);
// Extract resource path and domain from URL ready for fsockopen
$url = str_replace("http://","",$url);
$urlComponents = explode("/",$url);
$domain = $urlComponents[0];
$resourcePath = str_replace($domain,"",$url);
// Establish a connection
$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
if (!$socketConnection)
{
// You may wish to remove the following debugging line on a live Web site
// print("<!-- Network error: $errstr ($errno) -->");
} // end if
else {
$xml = '';
fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
// Loop until end of file
while (!feof($socketConnection))
{
$xml .= fgets($socketConnection, 128);
} // end while
fclose ($socketConnection);
} // end else
return($xml);
} // end function
?>
My code -is- fault tolerant... it works even if NOAA is down.