11.1.3 PHP日歷核心程序編寫
test.php
<?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"); //當前的日
//當年當月的天數(shù)
$days = date("t", mktime(0,0,0, $month, 1, $year));
//獲取當月的第一天是星期幾
$startweek = date("w", mktime(0,0,0, $month, 1, $year));
echo "今天是{$year}年{$month}月{$day}日乙漓,是情人節(jié), 還是元宵節(jié)染苛!<br>";
echo '<table border="0" width="300" align="center">';
echo '<tr>';
echo '<th style="background:blue">日</th>';
echo '<th style="background:blue">一</th>';
echo '<th style="background:blue">二</th>';
echo '<th style="background:blue">三</th>';
echo '<th style="background:blue">四</th>';
echo '<th style="background:blue">五</th>';
echo '<th style="background:blue">六</th>';
echo '</tr>';
echo '<tr>';
for($i=0; $i<$startweek; $i++) {
echo "<td> </td>";
}
for($j=1; $j <= $days; $j++) {
$i++;
if($j==$day) {
echo "<td style='background:green'>{$j}</td>";
}else{
echo "<td>{$j}</td>";
}
if($i%7 ==0 ){
echo '</tr><tr>';
}
}
while($i%7!==0) {
echo '<td> </td>';
$i++;
}
echo '</tr>';
echo '</table>';