\n\n". "Calendar\n\n\n\n\n"; } //----------------- This function is to do the HTML footer chore--------------------- function print_HTML_footer() { echo ""; } //----------------- This function prints calendar--------------------- function print_calendar($mon,$year) { global $dates, $first_day, $start_day; $first_day = mktime(0,0,0,$mon,1,$year); $start_day = date("w",$first_day); $res = getdate($first_day); $month_name = $res["month"]; $no_days_in_month = date("t",$first_day); //If month's first day does not start with first Sunday, fill table cell with a space for ($i = 1; $i <= $start_day;$i++) $dates[1][$i] = " "; $row = 1; $col = $start_day+1; $num = 1; while($num<=31) { if ($num > $no_days_in_month) break; else { $dates[$row][$col] = $num; if (($col + 1) > 7) { $row++; $col = 1; } else $col++; $num++; }//if-else }//while $mon_num = date("n",$first_day); $temp_yr = $next_yr = $prev_yr = $year; $prev = $mon_num - 1; $next = $mon_num + 1; //If January is currently displayed, month previous is December of previous year if ($mon_num == 1) { $prev_yr = $year - 1; $prev = 12; } //If December is currently displayed, month next is January of next year if ($mon_num == 12) { $next_yr = $year + 1; $next = 1; } echo "
"; echo "\n". "". ""; echo "\n"; echo ""; echo ""; $end = ($start_day > 4)? 6:5; for ($row=1;$row<=$end;$row++) { for ($col=1;$col<=7;$col++) { if ($dates[$row][$col] == "") $dates[$row][$col] = " "; if (!strcmp($dates[$row][$col]," ")) $count++; $t = $dates[$row][$col]; //If date is today, highlight it if (($t == date("j")) && ($mon == date("n")) && ($year == date("Y"))) echo "\n"; else //If the date is absent ie after 31, print space echo "\n"; }// for -col if (($row + 1) != ($end+1)) echo "\n"; else echo ""; }// for - row echo "\n
". "<< ".date("F",$first_day)." ".$temp_yr." ". ">>
SunMonTueWedThuFriSat
".$t."".(($t == " " )? " " :$t)."


Show Current month
"; } //----------Main Loop----------- print_HTML_header(); //If $month is not present, set it to current month. $month = (empty($month)) ? date("n") : $month; //If $year is not present, set it to current year. $year = (empty($year)) ? date("Y") : $year; print_calendar($month,$year); print_HTML_footer(); ?>