I'd like to know if it's possible to calculate the current moon phase or get it from somewhere (www, rss, I don't know..) in PHP.
Basically I need to display an image in a website depending on the current moon phase.
I found this: http://jivebay.com/2010/01/04/calculating-the-moon-phase-part-2/ , however, the author says it's not 100% accurate.
Any ideas ? thanks!
// calculate lunar phase (1900 - 2199)
$year = date('Y');
$month = date('n');
$day = date('j');
if ($month < 4) {$year = $year - 1; $month = $month + 12;}
$days_y = 365.25 * $year;
$days_m = 30.42 * $month;
$julian = $days_y + $days_m + $day - 694039.09;
$julian = $julian / 29.53;
$phase = intval($julian);
$julian = $julian - $phase;
$phase = round($julian * 8 + 0.5);
if ($phase == 8) {$phase = 0;}
$phase_array = array('new', 'waxing crescent', 'first quarter', 'waxing gibbous', 'full', 'waning gibbous', 'last quarter', 'waning crescent');
$lunar_phase = $phase_array[$phase];
Why do you want to use an RSS feed, why don't you calculate the current phase yourself like explained here: Calculate Moon Phase Data with PHP which is referencing this Moon Phase PHP class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With