Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display an image according to the moon phase

Tags:

php

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!

like image 694
Shaz Avatar asked Oct 27 '25 03:10

Shaz


2 Answers

// 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];
like image 172
LukeAmerica2020 Avatar answered Oct 29 '25 19:10

LukeAmerica2020


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.

like image 25
Dennis G Avatar answered Oct 29 '25 18:10

Dennis G