Fun with PHP

Posted by Andrew Flanagan

A neat little bit of code to display sunrise and sunset (the functions are built into PHP but I’m guessing many people don’t realize).

<?php
    $lat = 47.133031;
    $lon = -122.274538;
    $zenith=90+50/60;
    $offset=0;
    $location = "Puyallup, WA";
 
    $sunrise=date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, $lat, $lon, $zenith, $offset);
    $sunset=date_sunset((time() + (12 * 60 * 60)), SUNFUNCS_RET_TIMESTAMP, $lat, $lon, $zenith, $offset);
 
    $message = "<ul>";
 
    if (date("U", $sunrise) < date("U", time()))
    {
        $message .= "The sun rose today at ";
    }
    else
    {
        $message .= "The sun will rise today at ";
    }
 
    $message .= date("g:i a", $sunrise);
    if (date("U", $sunset) < date("U", time()))
    {
        $message .= " and the sun set today at ";
    }
    else
    {
        $message .= " and the sun will set today at ";
    }
 
    $message .= date("g:i a", $sunset);
 
    $message .= "</ul>";
 
    echo($message);
?>

Share and Enjoy:
  • Digg
  • Sphinn
  • Mixx
  • Google
  • Fark
  • Furl
  • StumbleUpon

Andrew Flanagan on February 20th 2007 in Geekiness

3 Responses to “Fun with PHP”

  1. Sarah responded on 21 Feb 2007 at 11:18 am #

    You are silly! Computer geekie husband!!!!!!!

  2. Peter responded on 22 Feb 2007 at 2:24 pm #

    An important question: “Why is it built into PHP?”

    My best guess (so far) is that the people who designed PHP were vampires.

    Or trolls.

    Or terribly romantic.

    Love ya, bro,

    -Peter

  3. Peter responded on 12 Mar 2007 at 11:43 am #

    Just curious - has it adapted to the new DST?
    Love,
    Peter

Trackback URI | Comments RSS

Leave a Reply