加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP输出日历表代码实例

发布时间:2020-12-12 20:47:53 所属栏目:PHP教程 来源:网络整理
导读:div class="jb51code" pre class="brush:php;" !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"gt; html xmlns="http://www.w3.org/1999/xhtml"gt; 月历表 function PrintMon($y
");
echo("<tr>");
for ($i=0; $i<7; $i++) //输出星期几
{
echo("<td width="90",height="40" align="center" >");
echo("

$WEEK[$i]

");
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("

$theDay

");
$startdate = strtotime("+1 day",$startdate); //日期前移1天
$theDate = getdate($startdate);//更新日期
$theWeek = ($theWeek + 1) % 7;//更新星期
}
echo("</td>");
}
echo("</tr>");
if ($startdate == $enddate) //如果已经输出全部日期,结束循环
{
$i = 6;
}
}

echo("</table");
}
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

请输入要查看的年号和月份(查询范围为1970年1月1日至2038年)

<?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("月份不对" . "
");
}
}
else if($year != NULL)
{
echo("年份不对" . "
");
}
?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

<div class="jb51code">
<pre class="brush:php;">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;

月历表 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("

$ym

    推荐文章
      热点阅读