1. New a Calendar class
2. Initialize the data in the two drop-down boxes, year and month
3. Initialize the year and month to be searched
4. Calculate the data information of each day in the calendar, including css and number of days
Refer to the previously encapsulated Calendar class
<?php include_once 'calendar.php'; ?>
The include_once() statement is included and included during script execution Run the specified file. This behavior is similar to the include() statement, the only difference is that if the code in the file is already included, it will not be included again. As the name of this statement implies, it will only be included once.
Instantiate this class:
<?php $util = new Calendar(); ?>
You also need to define the year and month arrays and obtain them through POST
<?php $years = array(2014, 2015, 2016, 2017, 2018);//年份选择自定义 $months = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);//月份数组 //获取post的年份数据 if(empty($_POST['ddlYear'])) { $year = date('Y'); }else { $year = $_POST['ddlYear']; } //获取post的月份数据 if(empty($_POST['ddlMonth'])) { $month = date('n'); }else { $month = $_POST['ddlMonth']; } ?>
Get the threshold method, caculate method and draw method.
<?php $calendar = $util->threshold($year, $month);//获取各个边界值 $caculate = $util->caculate($calendar);//获取计算日历的天数与样式 $draws = $util->draw($caculate);//画表格,设置table中的tr与td ?>