カレンダー 11−1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja"><head>
<meta http-equiv="Content-type" content="text/html; charset=EUC-JP">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="../style.css">
<title>カレンダー</title></head>
<body><div class="file2">
1970年から2037年のカレンダーを見ることができます。
<form action="11_01_date.php" method="post">
<select name="year">
<?php
error_reporting(1);
$cnt = 1970;
while ($cnt < 2038){
if($cnt == date(Y)){
echo "<option value='$cnt' selected>$cnt</option>";
} else {
echo "<option value='$cnt'>$cnt</option>";
}
$cnt++;
}
?></select>
<select name="month">
<?php
$cnt = 1;
while ($cnt < 13){
if($cnt == date(n)){
echo "<option value='$cnt' selected>$cnt</option>";
} else {
echo "<option value='$cnt'>$cnt</option>";
}
$cnt++;
}
?></select>
<input type="submit" value="作成!">
</form>
<?php
$year = $_POST['year'];
$month = $_POST['month'];
if($year == null){
$year = date(Y);
}
if($month == null){
$month = date(n);
}
/*---------------------------------------------------------------------------*/
echo "<font size=5><b>$year 年 $month 月</b></font>";
echo "<table border ='1'><tr>¥n";
echo "<td bgcolor='#ffaaaa' align='center' width='35'><font size='5'><b>日</b></font></td>¥n";
echo "<td bgcolor='#ffffdd' align='center' width='35'><font size='5'><b>月</b></font></td>¥n";
echo "<td bgcolor='#ffffdd' align='center' width='35'><font size='5'><b>火</b></font></td>¥n";
echo "<td bgcolor='#ffffdd' align='center' width='35'><font size='5'><b>水</b></font></td>¥n";
echo "<td bgcolor='#ffffdd' align='center' width='35'><font size='5'><b>木</b></font></td>¥n";
echo "<td bgcolor='#ffffdd' align='center' width='35'><font size='5'><b>金</b></font></td>¥n";
echo "<td bgcolor='#ddddff' align='center' width='35'><font size='5'><b>土</b></font></td></tr>¥n";
/*---------------------------------------------------------------------------*/
$wtop = date(w,mktime(0,0,0,$month,1,$year)) ; /*指定月1日の曜日*/
for($dot1 = 0 ; $dot1 < $wtop ; $dot1++){ /*日付が始まる前の空白*/
echo "<td align='center'>・</td>¥n";
}
/*---------------------------------------------------------------------------*/
for( $day = 1 ; checkdate( $month, $day, $year ) ; $day++ ){ /*日付記述、最後に1を足すので32になるそれでも曜日を返す*/
if(($day+$wtop)%7 == 1){
echo "<tr>¥n<td align='center'><font size='5' color='red'><b>$day</b></font></td>¥n"; /*日曜日*/
} else if(($day+$wtop)%7 == 0){
echo "<td align='center'><font size='5' color='blue'><b>$day</b></font></td>¥n</tr>¥n"; /*土曜日*/
} else {
echo "<td align='center'><font size='5'><b>$day</b></font></td>¥n"; /*その他*/
}
}
/*---------------------------------------------------------------------------*/
$wend = date(w,mktime(0,0,0,$month,$day,$year)) ; /*指定月最終日の曜日$dayは32になっている*/
if($wend !=0){ /*もし32が日曜日すなわち0ならそれで終了*/
for($dot2 =0 ; $dot2 < 7-$wend ;$dot2++){ /*0以外は・が必要*/
echo "<td align='center'>・</td>";
}
}
echo "</tr></table>";
?></div></body></html>