我的源代码(php实现的简单万年历)代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "/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代表某个⽉的每⼀天
表格网站php源码//初始化数组$arr_days
for ($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">
<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>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。