PHP simple calendar implementation method, php calendar implementation
This example describes how to implement a simple PHP calendar. We will share this with you for your reference. The details are as follows:
The running effect is as follows:
The Code is as follows:
<? Php/** Created on August */SimCalendar ('1970-08 '); // display the Calendar function SimCalendar ($ date) for the month {/*** simple calendar output, this function requires the support of cal_days_in_month * @ param $ date Y-m to output the date */echo '<table border = "1"> <thead> <tr> <th> day </th> <th> 1 </th> <th> 2 </th> <th> 3 </th> <th> 4 </th> <th> 5 </th> <th> 6 </th> </tr> </thead> <tbody> '; $ date_array = explode ('-', $ date); $ start_week = 0; // The value starts from Sunday to 0 $ month = cal_days_in_month (CAL_GREGORIA N, $ date_array [1], $ date_array [0]); // number of days in the current month $ wstar = date ('w', strtotime ($ date. '-01'); // the current month starts from the day of the week $ rows = ceil ($ wstar + $ month)/7); // The total number of rows $ mday = 1; // for ($ I = 0; $ I <$ rows; $ I ++) {echo '<tr>'; for ($ d = 0; $ d <7; $ d ++) {$ nowday = 7 * $ I + $ d + $ start_week; if ($ nowday >=$ wstar & $ mday <= $ month) {$ temp = date ('D', strtotime ($ date. '-'. $ mday); echo '<td> '. $ temp. '</td>'; $ mday ++ ;} Else {echo '<td> </td>';} echo '</tr> ';} echo '</tbody> </table>';}?>