Calculate Moon Phase Data with PHP II

A little while ago I posted the code to a PHP-based moon phase calculation program, which was a translation of the Perl Astro::MoonPhase module. This application can calculate the phase of the moon for a particular date or set of dates, and is much more accurate than other PHP-based moon phase calculation programs I've seen.

Thanks to Alexander Cicovic, I noticed a silly error in the phasehunt() function that caused it to loop infinitely :-/ While I was digging into the code, I decided to also add the phaselist() function that was added to the latest Astro::MoonPhase module, version 0.60.

The moonphase.inc.php script can be easily include()'ed into your PHP apps. Also for bonus points I updated the moonphase.php sample script to include an example all three functions (phase, phaselist and phasehunt). So, here they are below:

moonphase.inc.php -- Moonphase Functions
moonphase.php -- Sample Code

Enjoy!

Update: This script is now available as a PHP class.

2 comments:

Alex Cicovic said...

Thank you Steve!

Works like a charm now :)

SteveZ said...

Awesome.