Moon, a php script
What is the current lunar phase? Let's ask it to my website.

This is a small script that can be used to calculate moon phases. It's the porting to php of some code lines written in C. I don't remember where I've found the original script, so I can't report the original coder. Sorry. Returning values:

• 0 -> New moon
• 1 -> Waxing crescent moon Right 1–49% visible Left 1–49% visible afternoon and post-dusk 3 pm
• 2 -> First quarter moon Right 50% visible Left 50% visible afternoon and early night 6 pm
• 3 -> Waxing gibbous moon Right 51–99% visible Left 51–99% visible late afternoon and most of night 9 pm
• 4 -> Full moon Fully visible Fully visible sunset to sunrise (all night) 12 midnight
• 5 -> Waning gibbous moon Left 51–99% visible Right 51–99% visible most of night and early morning 3 am
• 6 -> Third quarter moon Left 50% visible Right 50% visible late night and morning 6 am
• 7 -> Waning crescent moon Left 1–49% visible Right 1–49% visible pre-dawn and morning 9 am
• 0 -> Dark moon

```function GetMoon (\$y, \$m, \$d)
{
\$c = 0;
\$e = 0;
\$jd = 0.0;
\$b = 0;

if (\$m < 3) {
\$y = \$y -1;
\$m = \$m + 12;
}
\$m = \$m + 1;
\$c = 365.25 * \$y;
\$e = 30.6 * \$m;
\$jd = \$c + \$e + \$d-694039.09;  /* jd is total days elapsed */
\$jd /= 29.53; /* divide by the moon cycle (29.53 days) */
\$b = floor(jd); /* int(jd) -> b, take integer part of jd */
\$jd = \$jd - \$b;	/* subtract integer part to leave fractional part of original jd */
\$b = round(\$jd * 8); /* scale fraction from 0-8 and round by adding 0.5 */
\$b = \$b & 7; /* 0 and 8 are the same so turn 8 into 0 */
return \$b;
}
```

(ultimo agg. 20/12/12)

Il contenuto di questo sito è distribuito con Licenza Creative Commons Attribuzione - Condividi allo stesso modo 4.0 Internazionale.