万年历

PHP编写的万年历

<?php
header("Content-Type:text/html;charset=utf-8");
$year=isset($_GET['y'])?$_GET['y']:date('Y');//获取年份
$mon=isset($_GET['m'])?$_GET['m']:date('m');//获取月份
$daynums=date('t',mktime(0,0,0,$mon,1,$year));//该月有多少天?
$w=date('w',mktime(0,0,0,$mon,1,$year));//该月1号是星期几?
echo "<h2>{$year}年{$mon}月</h2>";
echo "<table border=1>";
echo "<tr>";
echo "<th style='color:red'>星期日</th>";
echo "<th>星期一</th>";
echo "<th>星期二</th>";
echo "<th>星期三</th>";
echo "<th>星期四</th>";
echo "<th>星期五</th>";
echo "<th style='color:green'>星期六</th>";
echo "</tr>";
$dd=1;
while ($dd<=$daynums){
	echo "<tr>";
	for ($i=0;$i<7;$i++){
		if ($dd<=$daynums && ($w<=$i || $dd!=1)){//???????????
			echo "<td>$dd</td>";
			$dd++;
		}else{
			echo "<td>&nbsp;</td>";
		}
	}
	echo "</tr>";
}
echo "</table>";
$prem=$nextm=$mon;//??????????????
$prey=$nexty=$year;//????????????
if ($prem<=1){
	$prem=12;
	$prey--;
}else{
	$prem--;
}
if($nextm>=12){
	$nextm=1;
	$nexty++;
}else {
	$nextm++;
}
echo "<a href='calendar.php?y={$prey}&m={$prem}'>上一月</a>&nbsp;&nbsp;";
echo "<a href='calendar.php?y={$nexty}&m={$nextm}'>下一月</a>";
?>

你可能感兴趣的:(PHP编写的万年历)