Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set("Europe/Sofia");
- function draw_calendar($month, $year){
- $calendar = date('M', mktime(0, 0, 0, $month, 1, $year)) . '<br/>';
- //that string will contain the table and everything in it, we`ll add cells and rows to it
- $calendar .= '<table>';
- $counter = 1;
- //contans all headers that will be the same for every month
- $headers = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
- //we have to add these headings to the table using concatenation
- $calendar .= '<tr class="table-row"><td class="table-cell">' . implode('</td><td class="table-cell">', $headers) . '</td></tr>';
- /* numeric representations of the days of the week */
- $days_of_the_week = date('w', mktime(0, 0, 0, $month, 1, $year));
- /* total days in a month - 28 to 31 */
- $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
- //let`s print blank cells until the first day of the week - today is thursday so from 0 to 3 it will print blank cells
- $calendar .= '<tr class="calendar-row">';
- for($i = 0; $i < $days_of_the_week ;$i++) {
- $calendar .= '<td class="empty-cells"> </td>';
- }
- //continue for the rest of the days
- for($i = $days_of_the_week; $i <= $days_in_month ;$i++) {
- $calendar .= '<td class="table-cells">';
- $calendar .= '<div class="table-cell-info">' . $counter . '</div>';
- $calendar .= '</td>';
- $counter++;
- if($days_of_the_week == 6) {
- $calendar .= '</tr>';
- $days_of_the_week = -1;
- if($counter != $days_in_month) {
- $i--;
- }
- }
- $days_of_the_week++;
- }
- return $calendar;
- }
- //echo date('t', mktime(0, 0, 0, 8, 1, 2014));
- $inputYear = 2014;
- //echo date('M', mktime(0, 0, 0, 1, 1, 2014));
- for($i = 1; $i <= 12 ;$i++) {
- echo draw_calendar($i, $inputYear);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement