• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 765
  • Last Modified:

Moon Phase

I'd like to modify this moon phase script to replace New Moon, Waxing Crescent Moon, Quarter Moon, Waxing Gibbous Moon, Full Moon, Waning Gibbous Moon, Last Quarter Moon and Waning Crescent Moon with an image to represent the current moon phase.

Example:
case 0:
            return 'images/newmoon.gif';
            break;

Thanks
<?php
function moon_phase($year, $month, $day)
{
	$c = $e = $jd = $b = 0;
	if ($month < 3)
	{
		$year--;
		$month += 12;
	}
	++$month;
	$c = 365.25 * $year;
	$e = 30.6 * $month;
	$jd = $c + $e + $day - 694039.09; //jd is total days elapsed
	$jd /= 29.5305882; //divide by the moon cycle
	$b = (int) $jd; //int(jd) -> b, take integer part of jd
	$jd -= $b; //subtract integer part to leave fractional part of original jd
	$b = round($jd * 8); //scale fraction from 0-8 and round
	if ($b >= 8 )
	{
		$b = 0;//0 and 8 are the same so turn 8 into 0
	}
	switch ($b)
	{
		case 0:
			return 'New Moon';
			break;
		case 1:
			return 'Waxing Crescent Moon';
			break;
		case 2:
			return 'Quarter Moon';
			break;
		case 3:
			return 'Waxing Gibbous Moon';
			break;
		case 4:
			return 'Full Moon';
			break;
		case 5:
			return 'Waning Gibbous Moon';
			break;
		case 6:
			return 'Last Quarter Moon';
			break;
		case 7:
			return 'Waning Crescent Moon';
			break;
		default:
		return 'Error';
	}
}
$timestamp = time();
echo moon_phase(date('Y', $timestamp), date('n', $timestamp), date('j', $timestamp));
?>

Open in new window

0
Michael
Asked:
Michael
  • 3
  • 2
1 Solution
 
ronan1979Commented:
your example is correct

 what is your issue?
0
 
ronan1979Commented:
then

<?php

$img_path = moon_phase(date('Y', $timestamp), date('n', $timestamp), date('j', $timestamp));
?>

<img src="<?php echo $img_path?>" />
0
 
MichaelAuthor Commented:
The image does not appear, instead it returns copy that reads as:

images/newmoon.gif
0
 
ronan1979Commented:
insert the path in a html tag : <img src="img_path" />
0
 
MichaelAuthor Commented:
Thanks for the help!!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now