Moon phase calculation

hi,
i would like to get moon phase as full moon, new moon,first quarter, last quarter
for every month.i tried it but i didn’t get exact result.
could any one tell?

What’re you using to determine the phase?

So something like…


$numdays = array(0,31,(28+date('L',strtotime($y))),31,30,31,30,31,31,30,31,30,31);
function moon_phase($y, $m, $d)
{
    $c = $e = $b = 0;
    $jd = 0.0;

    if ($m < 3) {
        $y--;
        $m += 12;
    }
    $m++;
    $c = 365.25*$y;
    $e = 30.6*$m;
    $jd = $c+$e+$d-694039.09;
    $jd /= 29.53;
    $b = floor($jd);		   
    $jd -= $b;		   
    $b = $jd*8 + 0.5;	   
    $b = $b &#37; 7;		   
    return $b;
}
for($i = 1; $i <= $numdays[$m]; $i++) {
  $phase = moon_phase($y,$m,$i)
  switch($phase) {
     case 0:
        echo $i.": New Moon";
     break;
     case 2:
        echo $i.": First Quarter";
     break;
     case 4:
        echo $i.": Full Moon";
     break;
     case 6:
        echo $i.": Last Quarter";
     break;
     default:
     break;
}

(function moon_phase is not my code, btw)

i used month,year and timezone to determine the phase.