By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,262 Members | 2,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,262 IT Pros & Developers. It's quick & easy.

Simplest php web calendar?

P: n/a
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 ]

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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 .= '&nbsp;';
else{
$calendar .= $daycounter;
$daycounter++;
}
$calendar .= '</td>'."\n";
$weekdaycounter++;
}
$weekdaycounter = 1;
$calendar .= '</tr>'."\n";
}
$calendar .= '</table>'."\n";
echo $calendar;
?>
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.