function week_day_of_month($day,$month_num, $year) {
$days_in_month = array(1=>31, 2 => 28,...);//doesn't account for leap, you need to
$ts = strtotime(format_date($day,$month_num,$year));
$week_num = date('W', $ts);
$month_days = $days_in_month[$month_num];
for ($i = 1;$i<=$month_days;$i++) {
$ats = strtotime(format_date($i,$month_num, $year));
if ($ats == $ts)
break;
}
$day = $i;
return array($day,intval($week_num));
}
format_date just turns m,d,y into something strtotime can parse. you can handle leap by having two arrays within days of month 0=> non leap, 1=>leap. calculate leap is easy. and choose the correct array