O'Reilly logo

PHP Hacks by Jack D. Herrington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #25. Create an Interactive Calendar

Use PHP's date functions to create an interactive HTML calendar.

A calendar is often the best way to represent event data. It's something that your users are familiar with, and it is a great way to show lots of information in a small space. Pop-up calendar controls are available on the Web, and open source event calendar systems that include all the event management functionality you need are also available, but, at least when I looked, no simple calendar display controls that could show events in a calendar format were available. This hack creates a simple HTML calendar with controls for navigating back and forth through the months of the year.

The Code

Save the code in Example 3-20 as cal.php.

Example 3-20. Making calendaring work using PHP

<html>
<head>
<style type="text/css">
.calendar {
  font-family: arial, verdana, sans serif; 
}

.calendar td { border: 1px solid #eee; } .calendar-title { text-align: center; font-style: italic; } .calendar-day-title { text-align: center; font-size: small; background: #ccc; font-weight: bold; } .calendar-day, .calendar-outmonth-day { height: 60px; vertical-align: top; text-align: center; font-size: small; padding: 0px; } .calendar-day-number { text-align: right; background: #ddd; } .calendar-content { padding: 2px; font-size: x-small; } .calendar-outmonth-day { color: #666; font-style: italic; background: #ddd; } </style> </head> <body> <?php class Day { function Day( $inmonth, $month, $day, $year ) { $this->{'month'} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required