<?php
$now_year = date( 'Y' );
$now_month = date( 'n' );
$first_day = mktime( 0, 0, 0, $now_month, 1, $now_year );
$first_weekday = date( 'w' , $first_day );
?>
<html>
<head>
<meta charset="utf-8">
<title>今月のカレンダー</title>
</head>
<body>
<h3><?php echo $now_year; ?>年<?php echo $now_month; ?>月</h3>
<table border="1">
<tr>
<th class="sun">日</th>
<th>月</th>
<th>火</th>
<th>水</th>
<th>木</th>
<th>金</th>
<th class="sat">土</th>
</tr>
<?php
echo '<tr>';
$weekday = 0;
while( $weekday != $first_weekday ){
echo ('<td> </td>');
$weekday++;
}
for( $day = 1; checkdate( $now_month, $day, $now_year ); $day++ ){
if( $weekday > 6 ){
$weekday = 0;
echo ('</tr>' . "\n");
echo ('<tr>');
}
switch( $weekday ){
case 0 :
$color = 'red';
break;
case 6 :
$color = 'blue';
break;
default :
$color = 'black';
}
echo ('<td><font color=' .$color. ">" .$day. '</td>');
$weekday++;
}
while( $weekday < 7 ){
echo ('<td> </td>');
$weekday++;
}
echo ('</tr>' . "\n");
?>
</table>
</body>
</html>