<?php
$year = isset($_GET['year']) ? $_GET['year'] : date('y');
$month = isset($_GET['month'])? $_GET['month'] : date('m');
$day = isset($_GET['day']) ? $_GET['day'] : date('d');
$days = date('t', mktime(0,0,0, $month, 1, $year));
$startweek = date('w', mktime(0,0,0, $month, 1, $year));
echo "当天是{$year}年{$month}月{$day}日,这个月的1号是星期{$startweek}<br>";
echo '<table border="0px" width="500px" align="center">';
echo '<tr>';
echo '<th style="background-color: darkgrey">星期日</th>';
echo '<th style="background-color: darkgrey">星期一</th>';
echo '<th style="background-color: darkgrey">星期二</th>';
echo '<th style="background-color: darkgrey">星期三</th>';
echo '<th style="background-color: darkgrey">星期四</th>';
echo '<th style="background-color: darkgrey">星期五</th>';
echo '<th style="background-color: darkgrey">星期六</th>';
echo '</tr>';
echo '<tr>';
for($i = 0; $i<$startweek; $i++){
echo '<td> </td>';
}
for($j = 1; $j <= $days; $j++){
echo "<td align='center' >{$j}</td>";
$i++;
if($i % 7 ==0){
echo '</tr><tr>';
}
}
while($i%7 !== 0){
echo '<td> </td>';
$i++;
}
echo '</tr>';
echo '</table>';
?>