"; $calendar .= "$monthName $year"; $calendar .= ""; // Create the calendar headers foreach($daysOfWeek as $day) ( $calendar .= "$day"; ) // Create the rest of the calendar // Initiate the day counter, starting with the 1st. $currentDay = 1; $calendar .= ""; // The variable $dayOfWeek is used to // ensure that the calendar // display consists of exactly 7 columns. if ($dayOfWeek > 0) ( $calendar .= " "; ) $month = str_pad($month, 2, "0", STR_PAD_LEFT); while ($currentDay <= $numberDays) ( // Seventh column (Saturday) reached. Start a new row. if ($dayOfWeek == 7) ( $dayOfWeek = 0; $calendar .= ""; ) $currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT); $date = "$year-$month-$currentDayRel"; $calendar .= "$currentDay"; // Increment counters $currentDay++; $dayOfWeek++; ) // Complete the row of the last week in month, if necessary if ($dayOfWeek != 7) ( $remainingDays = 7 - $dayOfWeek; $calendar .= " "; ) $calendar .= ""; $calendar .= ""; return $calendar; ) ?>
использование
Чтобы распечатать таблицу за май 2005 г., просто выполните:
И вы получите такую таблицу:
Май 2005 г.S | M | Т | W | Т | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 год |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 год |