Posted By

jatkins on 10/26/11


Tagged

time calendar date


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

laxman2021


Calendar Generator (PHP)


 / Published in: PHP
 

Released into the public domain.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-loose.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Calendar</title>
  6. </head>
  7. <body>
  8. <?php
  9. function days_in_month($month, $year) {
  10. if($month!=2) {
  11. if($month==9||$month==4||$month==6||$month==11)
  12. return 30;
  13. else
  14. return 31;
  15. }
  16. else
  17. return $year%4==""&&$year%100!="" ? 29 : 28;
  18. }
  19.  
  20. global $months;
  21. $months = array(0 => 'January', 1 => 'February', 2 => 'March', 3 => 'April', 4 => 'May', 5 => 'June', 6 => 'July', 7 => 'August', 8 => 'September', 9 => 'October', 10 => 'November', 11 => 'December');
  22. $days = array(0 => 'Monday', 1 => 'Tuesday', 2 => 'Wednesday', 3 => 'Thursday', 4 => 'Friday', 5 => 'Saturday', 6 => 'Sunday');
  23.  
  24. function render_calendar($this_year = null) {
  25. if($this_year==null)
  26. $this_year = date('Y');
  27. $day_of_the_month = date('N', strtotime('1 January '.$this_year));
  28. for($i=0;$i<=11;$i++) {
  29. echo "<table>
  30. <caption>".$GLOBALS['months'][$i]."</caption>
  31. <thead>
  32. <tr>
  33. <th>Mon</th>
  34. <th>Tue</th>
  35. <th>Wed</th>
  36. <th>Thu</th>
  37. <th>Fri</th>
  38. <th>Sat</th>
  39. <th>Sun</th>
  40. </tr>
  41. </thead>
  42. <tbody>
  43. <tr>";
  44. for($n=1;$n<$day_of_the_month;$n++)
  45. echo "<td></td>\n";
  46. $days = days_in_month($i+1, $this_year);
  47. $day = 0;
  48. while($day<$days) {
  49. if($day_of_the_month==8) {
  50. echo ($day == 0 ? "" : "</tr>\n") . "<tr>\n";
  51. $day_of_the_month = 1;
  52. }
  53. echo "<td style=\"border: 1px solid red;\">" . ($day+1) . "</td>\n";
  54. $day_of_the_month++;
  55. $day++;
  56. }
  57. echo "</tr>
  58. </tbody>
  59. </table>";
  60. }
  61. }
  62.  
  63. render_calendar();
  64. ?>
  65. </body>
  66. </html>

Report this snippet  

You need to login to post a comment.