note 52574 deleted from ref.datetime by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 17:45:56 +0000 |
| Subject: | note 52574 deleted from ref.datetime by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133199@lists.php.net to get a copy of this message | ||
Note Submitter: r00t_ at mail dot ru
----
Function generate one month calendar like
February
Mon Tue Wed Thu Fri Sat Sun
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
(default in russian locale)
<?php
$year = (int)$_GET["year"];
$month = (int)$_GET["month"];
draw_month_cal($year, $month);
function draw_month_cal($year, $month, $locale = array ('ru_RU.CP1251',
'rus_RUS.1251'))
{
if (checkdate($month, 1, $year) && setlocale (LC_TIME, $locale)) {
if (!$day = date("w", $f_day = mktime(0, 0, 0, $month, 1, $year)))
$day = 7; // Mon first, Sun last
print "<table border=0><tr><th colspan=7>" .
strftime("%B", $f_day) . "</td></tr><tr>"; // Month
for ($i = 8; --$i;)
print "<th>" . strftime("%a", mktime(0, 0, 0, $month, 16 - $i - $day,
$year)) . "</th>"; // Mon Tue Wed Thu Fri Sat Sun
print "</tr><tr>" . str_repeat("<td></td>",
--$day); // Empty cells
while (checkdate($month, ++$i, $year)) { // $i==0 after for :-)
print "<td>$i</td>";
if (!(++$day % 7)) print "</tr><tr>"; // next line after Sun
}
print "</tr></table>";
}
}
?>