我的源代码(php实现的简单万年历)

来源:互联网 发布:php和java的区别 编辑:程序博客网 时间:2024/06/05 18:01

代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>calendar</title><meta name="Author" content="zhouyg1992"><meta name="Description" content="用php实现的一个简单万年历"><style type="text/css">table #week { text-align:center; background-color:#cccccc;}.weekday {color:red}table tr {text-align:center;background-color:#ffffcc;}#caption {font:bold 20px 幼圆,宋体;}#query {width:500px;height:10px;margin:50px auto;text-align:center;}</style></head><?php//如果您提交了时间则显示您提交年月的日历,否则显示当前月份日历if ($_GET['month'] && $_GET['year']){$month = $_GET['month'];$year = $_GET['year'];}else {$month = date ('m');$year = date ('Y');}$weekid = date ('w',mktime(0,0,0,$month,1,$year));//某年某月第一天是星期几。0-7分别代表星期日-星期六$countdays = date('t',mktime(0,0,0,$month,1,$year));//某年某个月的天数$arr_days = array ();//数组$arr_days代表某个月的每一天//初始化数组$arr_daysfor ($i = 0; $i <= 41; $i++){$arr_days[$i] = " ";}//给$arr_days数组赋值for ($i = $weekid, $j = 1; $j <= $countdays; $i++, $j++){$arr_days[$i] = $j;}?><body><form action="calendar.php"><div id="query"><input type="text" name="year">年<input type="text" name="month">月<input type="submit" value="查询"></div></form><table width="500px" height="300px" align="center"><caption><span id="caption"><?php echo $year ?>年<?php echo $month ?>月日历</span></caption><tr id="week"><td><span class="weekday">Sun</span></td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fir</td><td><span class="weekday">Sat</span></td></tr><?php//表格输出for ($i = 0; $i <= 41; $i++){if ($i % 7 == 0){echo '<tr>';}echo '<td>'.$arr_days[$i].'</td>';if (($i + 1) % 7 == 0){echo '</tr>';}}?></table></body></html>