<?php
class calendar
{
public $month;
public $year;
public function __construct($month, $year)
{
$this->month = $month;
$this->year = $year;
}
public function output()
{
$date = mktime(0, 0, 0, $this->month, 1, $this->year);
$week_num = date('W', $date);
$first_day = date('N', $date) - 1;
$count_days = date('t', $date);
$days = array(
'Mon' => 1,
'Tue' => 2,
'Wed' => 3,
'Thu' => 4,
'Fri' => 5,
'Sat' => 6,
'Sun' => 7,
);
$str - '';
$str .= '<h1>' . date('F Y', $date) . '</h1>';
$str .= '<table>';
$str .= '<tr>';
$str .= '<th></th>';
foreach($days as $day => $num)
{
$str .= '<th>' . $day . '</th>';
}
$str .= '</tr>';
$day = 1;
for($i = 0; $i < 6; $i++)
{
$str .= '<tr>';
$str .= '<td><strong>' . $week_num . '</strong></td>';
$week_num++;
for($j = 0; $j <7; $j++)
{
if($first_day > 0)
{
$first_day--;
$str .= '<td>';
$str .= '</td>';
}
elseif($count_days > 0)
{
$str .= '<td>';
$str .= $day++;
$str .= '</td>';
$count_days--;
}
else
{
$str .= '<td></td>';
}
}
$str .= '</tr>';
}
$str .= '</table>';
return $str;
}
}
$calendar = new calendar(8, 2007);
echo $calendar->output();
?>
Quicky mashed this out...
How can I improve on this?
What would you do differently and why?
Thank you for your feedback.