Difference between revisions of "PHP Calendar"
From KOP KB
								
												
				| Line 13: | Line 13: | ||
| $dayOfWeek = date('w', $firstDay); | $dayOfWeek = date('w', $firstDay); | ||
| ?> | ?> | ||
| + | </syntaxhighlight> | ||
| + | <syntaxhighlight lang="html4strict"> | ||
| <style> | <style> | ||
| + | </syntaxhighlight> | ||
| + | <syntaxhighlight lang="css"> | ||
| #today{ | #today{ | ||
| font-weight: bold; | font-weight: bold; | ||
| } | } | ||
| + | </syntaxhighlight> | ||
| + | <syntaxhighlight lang="html4strict"> | ||
| </style> | </style> | ||
| <table> | <table> | ||
| − | <caption><? echo($strMonth); ?></caption> | + | <caption> | 
| + | </syntaxhighlight> | ||
| + | <syntaxhighlight lang="php"> | ||
| + | <? echo($strMonth); ?> | ||
| + | </syntaxhighlight> | ||
| + | <syntaxhighlight lang="html4strict"> | ||
| + | </caption> | ||
| <thead> | <thead> | ||
| <tr> | <tr> | ||
| Line 34: | Line 46: | ||
| <tbody> | <tbody> | ||
| <tr> | <tr> | ||
| + | </syntaxhighlight> | ||
| + | <syntaxhighlight lang="php"> | ||
| <? | <? | ||
| if(0 != $dayOfWeek) { echo('<td colspan="'.$dayOfWeek.'"> </td>'); } | if(0 != $dayOfWeek) { echo('<td colspan="'.$dayOfWeek.'"> </td>'); } | ||
| Line 48: | Line 62: | ||
| } | } | ||
| ?> | ?> | ||
| + | </syntaxhighlight> | ||
| + | <syntaxhighlight lang="html4strict"> | ||
| </tr> | </tr> | ||
| </tbody> | </tbody> | ||
| </table> | </table> | ||
| </syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 23:40, 24 September 2014
<?php
// with php 5.3 it is you need to set timezone
date_default_timezone_set('America/Halifax');
$time = time();
$numDay = date('d', $time);
$numMonth = date('m', $time);
$strMonth = date('F', $time);
$numYear = date('Y', $time);
$firstDay = mktime(0,0,0,$numMonth,1,$numYear);
$daysInMonth = cal_days_in_month(0, $numMonth, $numYear);
$dayOfWeek = date('w', $firstDay);
?>
<style>
#today{
font-weight: bold;
}
</style>
<table>
<caption>
<? echo($strMonth); ?>
</caption>
<thead>
<tr>
<th abbr="Sunday" scope="col" title="Sunday">S</th>
<th abbr="Monday" scope="col" title="Monday">M</th>
<th abbr="Tuesday" scope="col" title="Tuesday">T</th>
<th abbr="Wednesday" scope="col" title="Wednesday">W</th>
<th abbr="Thursday" scope="col" title="Thursday">T</th>
<th abbr="Friday" scope="col" title="Friday">F</th>
<th abbr="Saturday" scope="col" title="Saturday">S</th>
</tr>
</thead>
<tbody>
<tr>
<?
if(0 != $dayOfWeek) { echo('<td colspan="'.$dayOfWeek.'"> </td>'); }
for($i=1;$i<=$daysInMonth;$i++) {
//this detects what day it is and adds an ID to it so you can css that particular one to make it stand out
if($i == $numDay) { echo('<td id="today">'); } else { echo("<td>"); }
echo($i);
echo("</td>");
if(date('w', mktime(0,0,0,$numMonth, $i, $numYear)) == 6) {
echo("</tr><tr>");
}
}
?>
</tr>
</tbody>
</table>
