November 2002
Intermediate to advanced
640 pages
16h 33m
English
The pc_calendar()
function shown in
Example 3-4 prints out a month’s
calendar, similar to the Unix cal program.
Here’s how you can use the function:
// print the calendar for the current month
list($month,$year) = explode(',',date('m,Y'));
pc_calendar($month,$year);The pc_calendar( ) function prints out a table
with a month’s calendar in it. It provides links to
the previous and next month and highlights the current day.
Example 3-4. pc_calendar( )
<?php function pc_calendar($month,$year,$opts = '') { // set default options // if (! is_array($opts)) { $opts = array(); } if (! isset($opts['today_color'])) { $opts['today_color'] = '#FFFF00'; } if (! isset($opts['month_link'])) { $opts['month_link'] = '<a href="'.$_SERVER['PHP_SELF'].'?month=%d&year=%d">%s</a>'; } list($this_month,$this_year,$this_day) = split(',',strftime('%m,%Y,%d')); $day_highlight = (($this_month == $month) && ($this_year == $year)); list($prev_month,$prev_year) = split(',',strftime('%m,%Y',mktime(0,0,0,$month-1,1,$year))); $prev_month_link = sprintf($opts['month_link'],$prev_month,$prev_year,'<'); list($next_month,$next_year) = split(',',strftime('%m,%Y',mktime(0,0,0,$month+1,1,$year))); $next_month_link = sprintf($opts['month_link'],$next_month,$next_year,'>'); ?> <table border="0" cellspacing="0" cellpadding="2" align="center"> <tr> <td align="left"> <?php print $prev_month_link ?> </td> <td colspan="5" align="center"> <?php print strftime('%B %Y',mktime(0,0,0,$month,1,$year)); ...Read now
Unlock full access