php万年历原型

<?php 
//计算当月天数
$days=date('t',strtotime('2017-11-1'));

$w=date('w',strtotime('2017-11-1'));

$firstday=1-$w;
 ?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>index</title>
</head>
<body>
<center>	
	<h2>2017年11月</h2>
	<table border='1px' width='700px' cellspacing="0">
		<tr>
			<th>星期日</th>
			<th>星期一</th>
			<th>星期二</th>
			<th>星期三</th>
			<th>星期四</th>
			<th>星期五</th>
			<th>星期六</th>
		</tr>	

		<?php 

			for($i=$firstday;$i<=$days;){
				echo "<tr>";
				for($j=1;$j<=7;$j++){
					if($i<=0 || $i>$days){
						echo "<td></td>";
					}else{
						echo "<td>{$i}</td>";
					}
					$i++;
				}
				echo "</tr>";
			}
		?>
		
	</table>
</center>
</body>
		</tr>
	</table>
</center>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/nuc_badaomen/article/details/78578795
今日推荐