TOP -> 作る!
-- カレンダーでも作る! --
<?php
// 現在の年
$year = date('Y');
// 現在の月
$month = date('m');
// 現在の年・月の1日
$day = mktime(0, 0, 0, $month, 1, $year);
// その月の最初の曜日
$first = date('w', $day);
// その月の日数
$total = date('t', $day);
// その月の週数
$week = ceil($total / 7);
if (($total % 7 > 7 - $first) || ($total % 7 == 0 && $first != 0)) {
$week++;
}
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th><font color="#FF0000">日</fonr></th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th><font
color="#000FFF">土</fonr></th>
</tr>
<tr>
<?php
echo $year . "年" . $month . "月";
for ($i=1;$i<=$week*7;$i++) {
if ($i % 7 == 1) {
echo "<tr>";
}
if (($i -1 < $first) || ($i > $total + $first)) {
echo "<td align=center><font color=#c0c0c0>・</font></td>";
} else {
if ($i % 7 == 1) {
$col = "#FF0000";
} elseif ($i % 7 == 0) {
$col = "#000FFF";
} else {
$col = "#000000";
}
echo "<td align=center><font color=" . $col . ">" . ($i - $first) . "</font></td>";
}
if ($i % 7 == 0) {
echo "</tr>";
}
}
?>
</tr>
</table>
表示結果:
2025年01月 |
日 | 月 | 火 | 水 | 木 | 金 | 土 |
・ | ・ | ・ | 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 | ・ |
-- 知ってるといいかも --
|