Advertisement
Valleri

Awesome Calendar

Aug 14th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2. date_default_timezone_set("Europe/Sofia");
  3.  
  4. function draw_calendar($month, $year){
  5.     $calendar = date('M', mktime(0, 0, 0, $month, 1, $year)) . '<br/>';
  6.     //that string will contain the table and everything in it, we`ll add cells and rows to it
  7.     $calendar .= '<table>';
  8.     $counter = 1;
  9.     //contans all headers that will be the same for every month
  10.     $headers = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
  11.     //we have to add these headings to the table using concatenation
  12.     $calendar .= '<tr class="table-row"><td class="table-cell">' . implode('</td><td class="table-cell">', $headers) . '</td></tr>';
  13.  
  14.     /* numeric representations of the days of the week */
  15.     $days_of_the_week = date('w', mktime(0, 0, 0, $month, 1, $year));
  16.     /* total days in a month - 28 to 31 */
  17.     $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
  18.  
  19.     //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
  20.     $calendar .= '<tr class="calendar-row">';
  21.  
  22.     for($i = 0; $i < $days_of_the_week ;$i++) {
  23.         $calendar .= '<td class="empty-cells"> </td>';
  24.     }
  25.  
  26.     //continue for the rest of the days
  27.     for($i = $days_of_the_week; $i <= $days_in_month ;$i++) {
  28.         $calendar .= '<td class="table-cells">';
  29.         $calendar .= '<div class="table-cell-info">' . $counter . '</div>';
  30.         $calendar .= '</td>';
  31.         $counter++;
  32.  
  33.         if($days_of_the_week == 6) {
  34.             $calendar .= '</tr>';
  35.             $days_of_the_week = -1;
  36.             if($counter != $days_in_month) {
  37.                 $i--;
  38.             }
  39.  
  40.         }
  41.         $days_of_the_week++;
  42.     }
  43.  
  44.     return $calendar;
  45. }
  46.  
  47. //echo date('t', mktime(0, 0, 0, 8, 1, 2014));
  48. $inputYear = 2014;
  49. //echo date('M', mktime(0, 0, 0, 1, 1, 2014));
  50. for($i = 1; $i <= 12 ;$i++) {
  51.     echo draw_calendar($i, $inputYear);
  52. }
  53.  
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement