?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>月历表</title>
<?php
$MONTH = array("元月","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
$enMONTH = array("元月","January" ,"February" ,"Marcy" ,"April" ,"May" ,"June" ,"July" ,"August" ,"September" ,"October" ,"November" ,"December");
$WEEK = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
$BACKCOLOR = array("#FFC" , "#FFF" , "#9F6" , "#FFC" , "#6F0" , "#6F6" , "#F90" , "#F06" , "#F00" , "#FC3" , "#FF6" , "#F99");
function PrintMon($year, $mon)
{
date_default_timezone_set("Asia/Shanghai");
global $MONTH;
global $enMONTH;
global $WEEK;
global $BACKCOLOR;
$startdate =strtotime("1 $enMONTH[$mon] $year"); //获取查询的年月
$enddate = strtotime("+1 month",$startdate); //获取下一个月的开始日期作为月历输出的截止时间
$theDate = getdate($startdate); //把日期转化为字符串格式
$color = $BACKCOLOR[$mon]; //设置月历的背景颜色
echo("<table border=\\"1\\" cellspacing=\\"0\\" cellpadding=\\"0\\" bgcolor=\\"$color\\">");
$ym = $year . "年". $MONTH[$mon];
echo("<caption><h1>$ym</h1></caption>");
echo("<tr>");
for ($i=0; $i<7; $i++) //输出星期几
{
echo("<td width=\\"90\\", height=\\"40\\" align=\\"center\\" >");
echo("<h2>$WEEK[$i]</h2>");
echo("</td>");
}
echo("</tr>");
$theWeek = $theDate[wday];//判断当天是星期几
for ($i=0; $i<6; $i++)
{
echo("<tr>");
for ($j=0; $j<7; $j++)
{
echo("<td width=\\"90\\", height=\\"40\\" align=\\"center\\" >");
if ($startdate < $enddate && $theWeek == $j)//把日期输出到对应的星期几所在列,并注意不要超出本月日期
{
$theDay = $theDate[mday];
echo("<h2>$theDay</h2>");
$startdate = strtotime("+1 day", $startdate); //日期前移1天
$theDate = getdate($startdate);//更新日期
$theWeek = ($theWeek + 1) % 7;//更新星期
}
echo("</td>");
}
echo("</tr>");
if ($startdate == $enddate) //如果已经输出全部日期,结束循环
{
$i = 6;
}
}
echo("</table");
}
?>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<h1>请输入要查看的年号和月份(查询范围为1970年1月1日至2038年)</h1>
<input type="text" name="myYear">年<input type="text" name="myMonth">月
<input type="submit">
</form>
<?php
$year = $_POST['myYear'];
$month = $_POST['myMonth'];
if (is_numeric($year) && $year >= 1970 && $year <2038)
{
if (is_numeric($month) && $month >= 1 && $month <=12)
{
PrintMon($year, $month);
}
else if($month != NULL)
{
echo("月份不对" . "<br />");
}
}
else if($year != NULL)
{
echo("年份不对" . "<br />");
}
?>
</body>
</html>
|
相关文章
猜你喜欢
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 26
-
2025-06-04 28
-
2025-05-29 20
-
2025-05-25 48
-
2025-05-29 19
热门评论

