WeatherLink has a tag for the name of the lunar phase name, but I couldn’t find one for WD, so I wrote a small PHP function to give you the text based on the contents of the WD %moonage% which has the age in days, hours, minutes and the % illumination.
I use it on my home page to display the phase name, the .gif of the moon, and the %illumination like this:
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td style="text-align: center;" class="data"><?php echo moonphase($moonage); ?></td>
</tr>
<tr>
<td style="text-align: center;"><img src="/images/moon<?php
$moonagedays = preg_replace('|^Moon age: (\d+)\s.*$|i',"\$1",$moonage);
echo $moonagedays; ?>.gif" alt="<?php
$t1 = moonphase($moonage) . ", Moon at $moonagedays days in cycle";
echo $t1; ?>" title="<?php echo $t1; ?>"
width="48" height="48" style="border: 0;" /></td>
</tr>
<tr>
<td style="text-align: center;" class="data" ><?php
echo $moonphase; ?>
Illuminated</td>
</tr>
</table>
The variables named are loaded by my testtags.php from a WD upload that sets them like this:
<?php
$moonage = "%moonage%"; // current age of the moon (days since new moon)
$moonphase = "%moonphase%"; // Moon phase %
?>
Sample contents of the variables substituted by WD are
<?php
$moonage = "Moon age: 26 days,13 hours,41 minutes,10%"; // current age of the moon (days since new moon)
$moonphase = "10%"; // Moon phase %
?>
Here’s the function that decodes $moonage into the text description
<?php
function moonphase ($WDmoonage) {
// decode WD %moonage% tag and return a text description for the moon phase name
// "Moon age: 10 days,10 hours,41 minutes,80%"
preg_match_all('|(\d+)|is',$WDmoonage,$matches);
// print "<!-- matches=\n" . print_r($matches,true) . "-->\n";
$mdays = $matches[1][0];
$mhours = $matches[1][1];
$mmins = $matches[1][2];
$mpct = $matches[1][3];
$mdaysd = $mdays + ($mhours / 24) + ($mmins / 1440);
// Definitions from http://www.answers.com/topic/lunar-phase
// * Dark Moon - Not visible
// * New Moon - Not visible, or traditionally, the first visible crescent of the Moon
// * Waxing Crescent Moon - Right 1-49% visible
// * First Quarter Moon - Right 50% visible
// * Waxing gibbous Moon - Right 51-99% visible
// * Full Moon - Fully visible
// * Waning gibbous Moon - Left 51-99% visible
// * Third Quarter Moon - Left 50% visible
// * Waning Crescent Moon - Left 1-49% visible
// * New Moon - Not visible
if ($mdaysd <= 29.53/2) { // increasing illumination
$ph = "Waxing";
$qtr = "First";
} else { // decreasing illumination
$ph = "Waning";
$qtr = "Last";
}
if ($mpct < 1 ) { return("New Moon"); }
if ($mpct <= 49) { return("$ph Crescent"); }
if ($mpct < 51) { return("$qtr Quarter"); }
if ($mpct < 99) { return("$ph Gibbous"); }
return("Full Moon");
}
?>
I’ve zipped up a set of moonNN.gif files at http://saratoga-weather.org/moon.zip if you need 'em.
Enjoy!
Best regards,
Ken