basic-web-php-PHP-Example01.php / php
<?php // Set up the variables (today, month, year, cmd) // today = m/d/y function setvars() { // Default is today month = year = today = today['mday']."/".// Return vars in an array return array("today" => today, "month" => year); } // End setvars() // Do the document header function docheader(year) { month."/1/".// If content header has not been sent, // send it if (!headers_sent()) { header('Content-type: text/html'); } // Print the document header (up to first date row) print <<<HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1.dtd"> <html> <head> <title>Calendar - Month </title> <style type="text/css"> tr.weekdays td { width: 100px; text-align: center; } tr.week td { width: 100px; height: 100px; color: black; } </style> </head> <body> <table border="1"> <!-- Controls and calendar title (month) --> <tr> <td colspan="7" align="center"> <strong> month_text </strong> </td> </tr> <!-- Day of week header row --> <tr class="weekdays"> <th>Sunday</th> <th>Monday</th> <th>Tuesday</th> <th>Wednesday</th> <th>Thursday</th> <th>Friday</th> <th>Saturday</th> </tr> <!-- Calendar (days) start here --> HTML; } // End docheader() // Do the document footer (close tags, end doc) function docfooter() { print <<<HTML <!-- Close all open tags, end document --> </table> </body> </html> HTML; } // End docfooter() // Print an empty day (cell) function emptyday() { print <<<HTML <td align="right" valign="top"> </td> HTML; } // End emptyday() // Print a day cell function day(today,day,curday = day."/".curday == font = " style=\"color: red;\""; } else { <td align="right" valign="top" font></td> HTML; } // End day() // Open or close a row function weekrow(cmd) { switch (<tr class=\"week\">\n"; break; case "close": print "</tr>\n"; break; } } // End weekrow() // Main program body function main() { // Set the date vars vars = setvars(); vars['today']; vars['month']; vars['year']; // Do the header and open first row docheader(year); weekrow("open"); // Set up first weekday and 1st day (m/1/y) month."/1/".day = 1; // Print empty days up to the first weekday of month for (weekday < weekday++) { emptyday(); } // Do rest of month while we have a valid date while (checkdate(day,// If SUN, open the row if (weekday == 1) { weekrow("open"); } // Print day and increment day(month,year); day++; // If SAT, close row reset weekday if (weekday = 1; } } // Close current week while (weekday <= 7) { emptyday(); // Close document docfooter(); } // End main(); // Kick it all off main(); ?>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.