For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > June 2005 > Simplest php web calendar?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Simplest php web calendar?
Sugapablo

2005-06-09, 8:56 pm

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.


--
[ Sugapablo ]
[ http://www.sugapablo.net <--personal | http://www.sugapablo.com <--music ]
[ http://www.2ra.org <--political | http://www.subuse.net <--discuss ]

Bert Melis

2005-06-09, 8:56 pm

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 = w starts on monday, 0 = w 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;
$wdaycounter = 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($wdaycounter <= 7){
if($daycounter==$day) $calendar .= '<td
class="calendartoday">';
else $calendar.='<td>';
if(($wdaycounter<=$offset AND $daycounter==1) OR
$daycounter>$numberofdays) $calendar .= ' ';
else{
$calendar .= $daycounter;
$daycounter++;
}
$calendar .= '</td>'."\n";
$wdaycounter++;
}
$wdaycounter = 1;
$calendar .= '</tr>'."\n";
}
$calendar .= '</table>'."\n";


echo $calendar;
?>
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com