Posted By

muenchnerhai on 01/09/19


Tagged

view calendar monospaced


Versions (?)

Simple calendar monthly view


 / Published in: PHP
 

A simple monospaced view of current month using server locales for naming days of the week

Todo: - implement configuration of first day of the week (So/Mo) - translate variables to English

  1. date_default_timezone_set('CET'); // Central European Time
  2. setlocale(LC_TIME, "de_DE.utf8"); // German
  3.  
  4. $kal_datum = time(); // comment to use fixed date for testing purposes
  5. //$kal_datum = mktime(0, 0, 0, 2, 18, 2008); // uncomment to use fixed date for testing purposes
  6.  
  7. $kal_jahr = intval(date("Y",$kal_datum));
  8. $kal_monat = intval(date("n",$kal_datum));
  9. $kal_tag = intval(date("j",$kal_datum));
  10.  
  11. echo "<pre>";
  12.  
  13. for( $i = 0; $i < 7; $i++ ) {
  14. echo strftime('%a', strtotime('next Monday +'.$i.' days'))."\t";
  15. }
  16. echo "<br />";
  17.  
  18. for($i=1; $i<=date("t",$kal_datum); $i++) {
  19. $WT = intval(date("N",mktime(0, 0, 0, $kal_monat, $i, $kal_jahr)));
  20. if ($i==1&&$WT!=1) {
  21. for ($j=1; $j<$WT; $j++) {echo " \t";};
  22. };
  23. if ($i==$kal_tag) {echo "<span style='color:#f00;'>";};
  24. if ($i<=9) {echo " ";};
  25. echo "$i";
  26. if ($i==$kal_tag) {echo "</span>";};
  27. echo "\t";
  28. if ($WT==7) {echo "<br />";};
  29. }
  30.  
  31. echo "</pre>";

Report this snippet  

You need to login to post a comment.