Fun with PHP


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);
?>

  1. #1 by Sarah on February 21, 2007 - 11:18 am

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

  2. #2 by Peter on February 22, 2007 - 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. #3 by Peter on March 12, 2007 - 11:43 am

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

(will not be published)