Image display according to the phase of the moon

I would like to know if it is possible to calculate the current phase of the moon or get it from somewhere (www, rss, I don't know ..) in PHP.

Basically I need to display an image on a website depending on the current phase of the moon.

I found this: http://jivebay.com/2010/01/04/calculating-the-moon-phase-part-2/ , however the author says that it is not 100% accurate.

Any ideas? thank!

+3
source share
3 answers

Why you want to use the RSS feed, why don’t you calculate the current phase yourself, as described here: Calculate the moon phase data using PHP , which refers to this PHP phase phase class .

+3
// 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];
+4

Source: https://habr.com/ru/post/1778125/


All Articles