Introduction to making a simple calendar in PHP development

Calendars are often used in daily work and development projects. Generally, developers use various calendar JS and JQ plug-ins to implement functions.

Here we use PHP to create a calendar of our own for your study and reference.

113.png

As shown in the figure, we initialize two drop-down boxes, one showing the year and one showing the month. Select the required year and month and click to modify. Calculate the data information of each day in the calendar, including css, day number

The left and right sides are displayed as rest days, and the background color setting is different from the working day.

Here you need to set up a class to generate each boundary value of the calendar, get the number of days in each month, the day of the week on the 1st of each month, and the day of the week on the last day of each month

What day of the week is the last day of the previous month, what day of the week is the first day of the next month, what day of the week is the first day of the set starting year and month, and so on.

Since the number of days and weeks of each month is constantly changing, it is necessary to concatenate the last left day of the week of the previous month and the first day of the next month to achieve the overall function.

1) Calculate the number of days in the last month. If the first day of the month is not Sunday, you need to calculate it based on the last day of the last month.

2) Calculate the number of days in this month The number of days is traversed, and if it is a rest day, add a special css style

3) Calculate the number of days in the next month, divided into three situations, Sunday, Saturday and working days

data It will be displayed using the table tag, so here we need to arrange the td under each tr.


Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"/> <title>PHP日历</title> </head> <body> </body> </html>
submitReset Code