Compute Sunrise and Sunset Taking Into Account Daylight Savings in PHP

A requirement came up to plot some graphs with surface sun indicated, and it is useful to show the sun rise and sun set.

The following code snippet shows how to do this when providing a latitude, longitude and day name (Monday through Sunday).

    $gDay = "Friday";
    $gLat = "51.1";
    $gLongs = "0.5"; // "-99.99" would be west of the Greenwich Meridian

    // GMT or BST?
    if (date('I', time())) {
    	$iOffset = 1; // Daylight saving set == BST
    	$sSavings = "BST";
    } else {
    	$iOffset = 0; // GMT
    	$sSavings = "GMT";
    }
    // compute sunset and rise using $gDay ... as this changes the further out in days you go
    if (($iTime = strtotime("next ".$gDay)) === false) {
	$sSunset = date_sunset(time(), SUNFUNCS_RET_STRING, $gLat,$gLongs, 90, $iOffset);
	$sSunrise = date_sunrise(time(), SUNFUNCS_RET_STRING, $gLat,$gLongs, 90, $iOffset);
    } else {
	$sSunset = date_sunset($iTime, SUNFUNCS_RET_STRING, $gLat,$gLongs, 90, $iOffset);
	$sSunrise = date_sunrise($iTime, SUNFUNCS_RET_STRING, $gLat,$gLongs, 90, $iOffset);
    }
	
    $sTailName .= "\nSunrise: $sSunrise -> Sunset: $sSunset ($sSavings)";

The variable $sTailName contains the result as a printable string.