PHP Current Calender

This Code Creates this Months Current Calendar using PHP


PHP


<?php

    echo "<HTML>\n" . " <HEAD>\n" . " <STYLE>\n" . "BODY, TD, TH\n" . "{\n" . " font-family: Verdana;\n" . " font-size: 15pt;\n" . "}\n" . " </style>\n" . " </head>\n" . " <BODY>\n";
    
$month = "";

     if ($month == "" || $year == "") { $this_month = date("n"); $month_name = date("F"); $this_year = date("Y"); } 
     
     else { $this_month = date("n", mktime(0, 0, 0, $month, 1, $year)); $month_name = date("F", mktime(0, 0, 0, $month, 1, $year)); $this_year = date("Y", mktime(0, 0, 0, $month, 1, $year)); }  $last_month = $this_month - 1; $next_month = $this_month + 1; 
     
      if ($last_month == 12) $last_year = $this_year - 1; else $last_year = $this_year; 
      
      if ($next_month == 1) $next_year = $this_year + 1; 
      
      else $next_year = $this_year;
      
echo " <CENTER><B>Calendar for $month_name, $this_year</b></center><BR>\n" . " <TABLE align=\"center\" border=\"2\" bordercolor=\"#0000ff\" cellpadding=\"5\" cellspacing=\"0\">\n" . "<TR bgcolor=\"#ff00ff\">\n" . "<TH width=\"50\">Sun</th>\n" . "<TH width=\"50\">Mon</th>\n" . "<TH width=\"50\">Tue</th>\n" . "<TH width=\"50\">Wed</th>\n" . "<TH width=\"50\">Thu</th>\n" . "<TH width=\"50\">Fri</th>\n" . "<TH width=\"50\">Sat</th>\n" . "</tr>\n"; 

$first_day = date("w", mktime(0, 0, 0, $this_month, 1, $this_year)); $total_days = date("t", mktime(0, 0, 0, $this_month, 1, $this_year));  $week_num = 1; $day_num = 1; 

     while ($week_num <= 6) { echo "<TR>\n";
      
     for ( $i = 0; $i <= 6; $i++ ) { 
     
     if ($week_num == 1) { 
     
     if ($i < $first_day) $the_day = " "; 
     
     else if ($i == $first_day) { $the_day = 1; } } 
     
      else { 
            
      if ($the_day > $total_days) $the_day = " "; } 
             
echo "<TD height=\"50\" width=\"50\" valign=\"top\">$the_day</td>\n"; 

      if ($the_day != " ") $the_day++; } echo "</tr>\n";  $week_num++; } 
      
?>

Click here to run this code



More Free Code Examples:




Comments

Popular posts from this blog

Multi-tap Keypad Text Entry

Crypto Mining