| 
	
 | 
 Posted by Bert Melis on 06/09/05 23:26 
Sugapablo wrote: 
> Can someone recommend a very simple script to produce a web calendar? 
>  
> I just want something where I can select a month and year and it produces 
> a very basic HTML table, 7 columns across, one month at a time, with the 
> dates filled in. 
>  
> No frills, no nothing, just pure, month producing code. 
>  
>  
 
This is what I use. It maybe is f*cked up by the word-wrap of my  
newsreader... 
 
<?php 
 
$year = date('Y'); 
$month = date('m'); 
$day = date('d'); 
$months = array( 
	1=>'januari', 
	2=>'februari', 
	3=>'march', 
	4=>'april', 
	5=>'may', 
	6=>'june', 
	7=>'july', 
	8=>'august', 
	9=>'september', 
	10=>'october', 
	11=>'november', 
	12=>'december' 
); 
// 0 = sunday, 1 = monday etc... 
$days = array( 
	0=>'sun', 
	1=>'mon', 
	2=>'tue', 
	3=>'wed', 
	4=>'thu', 
	5=>'fri', 
	6=>'sat' 
); 
$startonmonday = 1; //1 = week starts on monday, 0 = week starts on sunday 
 
$numberofdays = date("t",mktime(0, 0, 0, $month, 1, $year)); 
$firstday = date("w",mktime(0, 0, 0, $month, 1, $year)); 
 
$offset = 0; 
if($startonmonday){ 
   if($firstday==0) $offset = 6; 
   else $offset = $firstday-1; 
} 
else $offset = $firstday; 
 
$daycounter = 1; 
$weekdaycounter = 1; 
$calendar = '<table class="calendar">'."\n".'<tr>'; 
if($startonmonday) { 
	for($i=1;$i<=6;$i++) $calendar .= '<th>'.$days[$i].'</th>'; 
	$calendar .= '<th>'.$days[0].'</tr>'; 
} 
else { 
	for ($i=0;$i<=6;$i++) $calendar .= '<th>'.$days[$i].'</th>'; 
} 
while($daycounter<=$numberofdays){ 
         $calendar .= "\n".'<tr>'."\n"; 
         while($weekdaycounter <= 7){ 
                 if($daycounter==$day) $calendar .= '<td  
class="calendartoday">'; 
                 else $calendar.='<td>'; 
                 if(($weekdaycounter<=$offset AND $daycounter==1) OR  
$daycounter>$numberofdays) $calendar .= ' '; 
                 else{ 
                         $calendar .= $daycounter; 
                         $daycounter++; 
                 } 
                 $calendar .= '</td>'."\n"; 
                 $weekdaycounter++; 
         } 
         $weekdaycounter = 1; 
         $calendar .= '</tr>'."\n"; 
} 
$calendar .= '</table>'."\n"; 
 
 
echo $calendar; 
?>
 
[Back to original message] 
 |