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($startonmond ay){
if($firstday==0 ) $offset = 6;
else $offset = $firstday-1;
}
else $offset = $firstday;
$daycounter = 1;
$weekdaycounter = 1;
$calendar = '<table class="calendar ">'."\n".'<tr>' ;
if($startonmond ay) {
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($daycount er<=$numberofda ys){
$calendar .= "\n".'<tr>'."\n ";
while($weekdayc ounter <= 7){
if($daycounter= =$day) $calendar .= '<td
class="calendar today">';
else $calendar.='<td >';
if(($weekdaycou nter<=$offset AND $daycounter==1) OR
$daycounter>$nu mberofdays) $calendar .= ' ';
else{
$calendar .= $daycounter;
$daycounter++;
}
$calendar .= '</td>'."\n";
$weekdaycounter ++;
}
$weekdaycounter = 1;
$calendar .= '</tr>'."\n";
}
$calendar .= '</table>'."\n";
echo $calendar;
?>