-
- //calendar.php
-
- /*******************************
- * Function to determine whether it is a leap year*
- * Can be improved based on more complex algorithms*
- ** *****************************/
- function leap_year($year)
- {
- if($year% 4 == 0) // basic rule
- {
- return true; // is leap year
- }
- else
- {
- return false;
- }
- }
-
- /*******************************
- * Assign values to some variables*
- * Pay special attention to the assignment in February*
- * ********************************/
- function setup()
- {
- global $mon_num;
- $mon_num=array(31,30,31,30,31,30,31,31,30,31,30,31);
- global $mon_name;
- $mon_name=array("一","二","三","四",
- "五","六","七","八",
- "九","十","十一","十二");
- if (leap_year($firstday[year])) // basic rule
- {
- $mon_num[1]=29; // is leap year
- }
- else
- {
- $mon_num[1]=28;
- }
- }
-
- /*******************************
- * Display a cell in the table*
- * The displayed content and color are variable*
- * ********************************/
- function showline($content,$show_color)
- {
- $begin_mark = "
";
- $begin_mark =$begin_mark."";
- $end_mark = "
| ";
- echo $begin_mark.$content.$end_mark ;
- }
- ?>
-
-
-
- Community Calendar
-
-
-
-
- //Get the current date
- $firstday = getdate(mktime(0,0,0, date("m"),1,date("Y")));
-
- setup();
- //Display the name of the table
- echo "";
- echo "
";
- echo "
";
- echo "";
- echo "$firstday[year]年 ".$mon_name [$firstday[mon]-1]."Month Calendar";
- echo "";
- echo "
| ";
-
- //Header
- $weekDay[0] = " day";
- $weekDay[1] = "one";
- $weekDay[2] = "two";
- $weekDay[3] = "three";
- $weekDay[4] = "four";
- $weekDay [5] = "five";
- $weekDay[6] = "six";
-
- echo "
";
-
- //Display table The first line of
- for ($dayNum = 0; $dayNum < 7; ++$dayNum) {
- showline($weekDay[$dayNum],"red");
- }
-
- echo"
";
- $toweek=$firstday[wday];//What day of the week is the first day of this month
- $lastday=$mon_num[$firstday[mon]-1];//What day of the week is the last day of this month
- $day_count = 1;//The current number of days that should be displayed
- $up_to_firstday = 1;//Whether it is displayed to the first day of this month
-
- for ($row = 0; $row <= ($lastday+$toweek-1 )/7; ++$row)//How many weeks are there in this month
- { echo "
";
- for ($col=1; $col<=7; ++$ col)
- {
- //Everything displayed before the first day is "empty"
- if (($up_to_firstday <= $toweek) ||($day_count>$lastday))
- {
- echo "
  | ";
- $up_to_firstday++;
- }
- else
- {
- //Show a day in this month
- showline($day_count,"blue");
- $day_count++;
- }
- }
- echo "< ;/TR>";
- }
-
- echo "
";
- echo "";
- ?>
-
>>>> Articles you may be interested in:
php calender calendar code (solve 2038 problem)
php calendar code (with demo effect)
php calendar code sharing simple and practical php calendar code
php calendar code efficient calendar code implemented in php
php calendar code Three good php calendar codes
PHP simple calendar implementation code (can bind events)
|