PHP output calendar code example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/"> <html xmlns="http:///1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Monthly calendar</title> <?php $MONTH = array("January","January","February","March","April","May","June","July","August","September","October","November","December"); $enMONTH = array("January","January" ,"February" ,"Marcy" ,"April" ,"May" ,"June" ,"July" ,"August" ,"September" ,"October" ,"November" ,"December"); $WEEK = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); $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"); //Get the year and month of the query $enddate = strtotime("+1 month",$startdate); //Get the start date of the next month as the deadline for the calendar output $theDate = getdate($startdate); //Convert date to string format $color = $BACKCOLOR[$mon]; //Set the background color of the calendar echo("<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"$color\">"); $ym = $year . "Year". $MONTH[$mon]; echo("<caption><h1>$ym</h1></caption>"); echo("<tr>"); for ($i=0; $i<7; $i++) //Output day of week { echo("<td width=\"90\", height=\"40\" align=\"center\" >"); echo("<h2>$WEEK[$i]</h2>"); echo("</td>"); } echo("</tr>"); $theWeek = $theDate[wday];//Judge the day of the week that day 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)//Output the date to the corresponding day of the week column, and be careful not to exceed the date of this month { $theDay = $theDate[mday]; echo("<h2>$theDay</h2>"); $startdate = strtotime("+1 day", $startdate); //The date is moved 1 day before $theDate = getdate($startdate);//Update date $theWeek = ($theWeek + 1) % 7;//Update week } echo("</td>"); } echo("</tr>"); if ($startdate == $enddate) //If all dates have been output, end the loop { $i = 6; } } echo("</table"); } ?> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <h1>Please enter the year number and month to view(The query scope is1970Year1moon1Sun to2038Year)</h1> <input type="text" name="myYear">Year<input type="text" name="myMonth">moon <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("The month is wrong" . "<br />"); } } else if($year != NULL) { echo("The year is wrong" . "<br />"); } ?> </body> </html>
Related Articles
Yii Framework Study Notes, Session and Cookie Simple Operation Examples
This article mainly introduces the session and cookie simple operation of Yii framework learning notes. It analyzes the simple operation techniques such as definition, setting, reading and writing, and deletion of Yii framework session and cookie in combination with examples. Friends who need it can refer to it.2019-04-04ThinkPHP3.1 new features are more complete in multi-database operations
For earlier versions of ThinkPHP, switching databases required using advanced models, and the current version 3.1 can be solved more easily. This article mainly introduces ThinkPHP3.1 to multi-database operations. Friends who need it can refer to it.2014-06-06php setting method of putting session into memcached
This article mainly introduces the setting method of php to put session into memcached. Friends who need it can refer to it2014-02-02PHP code to add text to the pictures you post at any time
PHP code to add text to the pictures you post at any time...2007-03-03Detailed explanation of Yii multi-table joint query operation
This article mainly introduces Yii multi-table joint query operation in detail, and summarizes Yii multi-table joint query operation. Interested friends can refer to it.2016-06-06Detailed interpretation of low memory utilization and weak types of PHP arrays
This article mainly introduces a detailed interpretation of the low memory utilization and weak types of PHP arrays, which has certain reference value. Interested friends can refer to it.2017-08-08Analysis of the reason why the php empty function judges that the result is empty but the actual value is non-empty
This article mainly introduces the reason why the php empty function is judged to be empty but the actual value is not empty. Below is the debugging record after my editor process it. Share it to my platform. Interested friends will take a look.2018-05-05How to improve truncate in smarty to support Chinese
This article mainly introduces the method of improving truncate in smarty to support Chinese, and involves relevant techniques for function function expansion for truncate source files in Smarty source code. Friends who need it can refer to it2016-05-05Zend Framework tutorial: Connecting to the database and performing additions, deleting and searching (with demo source code download)
This article mainly introduces the method of connecting to the database and performing addition, deletion and search in the Zend Framework tutorial. It analyzes the configuration of the Zend Framework database and the implementation methods of performing addition, deletion, modification and search in detail in combination with the example form. Friends who need it can refer to it.2016-03-03Yii's method of using Captcha verification code
This article mainly introduces Yii's method of using Captcha verification code, and analyzes Yii's three-layer MVC implementation techniques using Captcha verification code in combination with examples. Friends who need it can refer to it2015-12-12