Author Topic: Different tags at different times of day (PHP)  (Read 3542 times)

0 Members and 1 Guest are viewing this topic.

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
Different tags at different times of day (PHP)
« on: February 08, 2007, 03:59:55 AM »
Is is possible to show a sunrise time at night and then switch to a sunset time in the day?
South of the Tracks, Anchorage, KY

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
Re: Different tags at different times of day (PHP)
« Reply #1 on: February 10, 2007, 08:21:03 PM »
Well, there were no responses, so I tried to see if I could find a solution.  I was able to come up with this using the WeatherLink tags for sunrise and sunset.  However, is there a way to use the actual sunrise and sunset time to switch from one to the other (instead of hours of the day).  For example; if the sunset today is at 6:14pm; then at 6:15pm the tag changes from sunset to sunrise.


Code: [Select]

<?php
putenv
&#40;'TZ=America/New_York'&#41;;
$hour date&#40;"H"&#41;;

if &#40;$hour > 8 and $hour < 21&#41; &#123;
echo "Sunset&#58;  <!--SunsetTime-->";
&
#125;
else &#123;
echo "Sunrise&#58;  <!--SunriseTime-->";
&
#125;
?>

South of the Tracks, Anchorage, KY

Offline up10ad N9RJH

  • USA Weather Finder
  • WxElement panel
  • Forecaster
  • *****
  • Posts: 578
  • Station will be back up someday...
    • Forecaster without a site
Re: Different tags at different times of day (PHP)
« Reply #2 on: February 11, 2007, 11:30:57 AM »
It can be done using php5 with the new sunrise and sunset functions.  I tried it and the functions work well, unfortunately, I have to keep php4 active because of some poorly written old php code on my system that is beyond my ability to correct. The code for checking should look something like this:

Code: [Select]
<?php
if &#40;
&#40;gettimeofday&#40;&#41; < date_sunrise&#40;time&#40;&#41;,SUNFUNCS_RET_DOUBLE,38.4,-9,90,1&#41;&#41; || &#40;gettimeofday&#40;&#41; > date_sunset&#40;time&#40;&#41;,SUNFUNCS_RET_DOUBLE,38.4,-9,90,1&#41;&#41;
&#41;
&#123;
echo&#40;"Sunrise time&#58; "&#41;;
echo&#40;date_sunrise&#40;time&#40;&#41;,SUNFUNCS_RET_STRING,38.4,-9,90,1&#41;&#41;;
&#125;
else
&
#123;
echo&#40;"Sunset time&#58; "&#41;;
echo&#40;date_sunset&#40;time&#40;&#41;,SUNFUNCS_RET_STRING,38.4,-9,90,1&#41;&#41;;
&#125;
?>

[corrections form php gurus are encouraged]

The SUNFUNCS arguments need to reflect your location

//Latitude: 38.4 North
//Longitude: 9 West
//Zenith ~= 90
//offset: +1 GMT

I guess you could use similar code and replace the comparisons and output with either weatherlink tags or vws tags but you would need to get them into variables in the correct format.
Rick (N9RJH)
Have you joined USAWeatherFinder.com yet?

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
Re: Different tags at different times of day (PHP)
« Reply #3 on: February 11, 2007, 03:22:25 PM »
Quote from: "k6dyc"
It can be done using php5 with the new sunrise and sunset functions.  I tried it and the functions work well, unfortunately, I have to keep php4 active because of some poorly written old php code on my system that is beyond my ability to correct. The code for checking should look something like this:

Code: [Select]
<?php
if &#40;
&#40;gettimeofday&#40;&#41; < date_sunrise&#40;time&#40;&#41;,SUNFUNCS_RET_DOUBLE,38.4,-9,90,1&#41;&#41; || &#40;gettimeofday&#40;&#41; > date_sunset&#40;time&#40;&#41;,SUNFUNCS_RET_DOUBLE,38.4,-9,90,1&#41;&#41;
&#41;
&#123;
echo&#40;"Sunrise time&#58; "&#41;;
echo&#40;date_sunrise&#40;time&#40;&#41;,SUNFUNCS_RET_STRING,38.4,-9,90,1&#41;&#41;;
&#125;
else
&
#123;
echo&#40;"Sunset time&#58; "&#41;;
echo&#40;date_sunset&#40;time&#40;&#41;,SUNFUNCS_RET_STRING,38.4,-9,90,1&#41;&#41;;
&#125;
?>

[corrections form php gurus are encouraged]

The SUNFUNCS arguments need to reflect your location

//Latitude: 38.4 North
//Longitude: 9 West
//Zenith ~= 90
//offset: +1 GMT

I guess you could use similar code and replace the comparisons and output with either weatherlink tags or vws tags but you would need to get them into variables in the correct format.


Rick:

My server too is using 4.0.  I don't think this will work for me either.
South of the Tracks, Anchorage, KY