Share a simple PHP calendar code example
Echo $ begin_mark. $ content. $ end_mark;
}
?>
Community Calendar
// Obtain the current date
$ Firstday = getdate (mktime (0, 0, 0, date ("m"), 1, date ("Y ")));
Setup ();
// Display the table name
Echo" "; Echo"
- // Calendar. php
- /*******************************
- * Functions used to determine whether a leap year is used *
- * Improvements can be made 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 value assignment for February *
- *******************************/
- Function setup ()
- {
- Global $ mon_num;
- $ Mon_num = array (, 30, 31 );
- Global $ mon_name;
- $ Mon_name = array ("1", "2", "3", "4 ",
- "5", "6", "7", "8 ",
- "9", "10", "11", "12 ");
- If (leap_year ($ firstday [year]) // basic rule
- {
- $ Mon_num [1] = 29; // is leap year
- }
- Else
- {
- $ Mon_num [1] = 28;
- }
- }
-
- /*******************************
- * Display a grid in the table *
- * The displayed content and color are variable *
- *******************************/
- Function showline ($ content, $ show_color)
- {
- $ Begin_mark ="
|
";$ Begin_mark = $ begin_mark ."";$ End_mark =" | ";
Echo"
$ Toweek = $ firstday [wday]; // The first day of the month is the day of the week.
For ($ col = 1; $ col <= 7; ++ $ col)
$ Up_to_firstday ++;
}
// Header
$ WeekDay [0] = "day ";
$ WeekDay [1] = "1 ";
$ WeekDay [2] = "2 ";
$ WeekDay [3] = "3 ";
$ WeekDay [4] = "4 ";
$ WeekDay [5] = "5 ";
$ WeekDay [6] = "6 ";
Echo"
// Display the first row of the table
For ($ dayNum = 0; $ dayNum <7; ++ $ dayNum ){
Showline ($ weekDay [$ dayNum], "red ");
}
Echo"
$ Lastday = $ mon_num [$ firstday [mon]-1]; // The last day of the month is the day of the week.
$ Day_count = 1; // Number of days to be displayed
$ Up_to_firstday = 1; // whether it is displayed on the first day of the month
For ($ row = 0; $ row <= ($ lastday + $ toweek-1)/7; + + $ row) // this month has several weeks
{Echo"
{
// "Null" is displayed before the first day"
If ($ up_to_firstday <= $ toweek) | ($ day_count> $ lastday ))
{
Echo"
}
Else
{
// Display a day of the month
Showline ($ day_count, "blue ");
$ Day_count ++;
}
}
Echo"
Echo"
";
";Echo "";Echo "$ firstday [year] year". $ mon_name [$ firstday [mon]-1]. "Monthly & nbsp calendar ";Echo "";Echo" | ";
";
";
";
| ";
";
";
Echo"";
?>
>>> Articles you may be interested in: php calender calendar code (solving 2038 issues) php calendar code (with demo effect) php calendar code sharing simple and practical php calendar code php efficient calendar code php calendar code three good php calendar code php simple calendar implementation code (events can be bound)