我创建了以下函数,它打印从星期日(到星期六)开始的日历......但我希望能够选择任何一天作为第一天......例如。第一天是星期三...我试过但无法正常工作...你能帮我解决这个问题吗?
我知道如何操纵天标题数组来反映这个开始日,但日历天不知何故搞砸了。
function testme() {
$month = 8;
$year = 2012;
$days = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
echo $firstDayOfMonth = date('w',mktime(0,0,0,$month,1,$year)); // a zero based day number
$daysInMonth = date('t',mktime(0,0,0,$month,1,$year));
$calendar = ' <!-- start cal -->';
$calendar = '<table border="1" class="calendar">'."\r\n";
$calendar .= '<thead><tr><th class="calendar-day-head">'.implode('</th><th class="calendar-day-head">',$days ).'</th></tr></thead><tbody>';
$calendar .= "\r\n".'<tr class="calendar-row">';
$calendar .= str_repeat('<td class="calendar-day-np"> </td>', $firstDayOfMonth); // "blank" days until the first of the current week
$calendar .= '';
$dayOfWeek = $firstDayOfMonth + 1; // a 1 based day number: cycles 1..7 across the table rows
for ($dayOfMonth = 1; $dayOfMonth <= $daysInMonth; $dayOfMonth++)
{
$date = sprintf( '%4d-%02d-%02d', $year, $month, $dayOfMonth );
$calendar .= '';
$calendar .= '<td class="calendar-day">
'.$dayOfMonth.' <br />';
$calendar .= '';
$calendar .= '</td>'."\r\n";
if ($dayOfWeek >= 7)
{
$calendar.= '</tr>'."\r\n";
if ($dayOfMonth != $daysInMonth)
{
$calendar .= '<tr class="calendar-row">';
}
$dayOfWeek = 1;
}
else
{
$dayOfWeek++;
}
}
//echo 8-$dayOfWeek;
$calendar .= str_repeat('<td class="calendar-day-np"> </td>', 8 - $dayOfWeek); // "blank" days in the final week
$calendar .= '</tr></table>';
$calendar .= ' <!-- end cal -->';
echo $calendar;
}