search
Homephp教程php手册PHP输出日历表代码实例,php输出日历实例

PHP输出日历表代码实例,php输出日历实例

<!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>
<&#63;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 id="ym">$ym</h1></caption>");
 echo("<tr>");
 for ($i=0; $i<7; $i++) //输出星期几
 {
 echo("<td width=\"90\", height=\"40\" align=\"center\" >");
 echo("<h2 id="WEEK-i">$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 id="theDay">$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");
 } 
&#63;>


</head>


<body>


<form method="post" action="<&#63;php echo $_SERVER['PHP_SELF'];&#63;>">
<h1 id="请输入要查看的年号和月份-查询范围为-年-月-日至-年">请输入要查看的年号和月份(查询范围为1970年1月1日至2038年)</h1>
<input type="text" name="myYear">年<input type="text" name="myMonth">月
<input type="submit">
</form>


<&#63;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 />");
 }
&#63;>


</body>
</html>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor