指定した月のカレンダーを表示してみます。
<?php
$year = 2012;
$month = 8;
$datetime = new DateTime();
$datetime->setDate($year, $month, 1);
$lastday = (int)$datetime->format('t');
$w = (int)$datetime->format('w');
?>
<table>
<tr>
<th>日</th>
<th>月</th>
<th>火</th>
<th>水</th>
<th>木</th>
<th>金</th>
<th>土</th>
</tr>
<tr>
<?php
//空白で埋める
for($i=0;$i < $w;$i++){
echo "<td>-</td>\n";
}
$day = 1;
for($cell=$w;$cell < 35;$cell++){
if($cell % 7 == 0){
echo "</tr>\n<tr>\n";
}
if($day <= $lastday){
echo "<td>{$day}</td>\n";
} else {
echo "<td>-</td>\n";
}
$day++;
}
?>
</tr>
</table>
結果(例):
