folgende Ausgabe würde ich gerne als einzige Variable zusammenfassen:
Code: Alles auswählen
//This gets todays date
$date =time ();
//This puts the day, month, and year in seperate variables
$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);
//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year);
//This get's us the month name
$title = date('F', $first_day);
//Here we find out what day of the week the first day of the month falls on
$day_of_week = date('D', $first_day);
//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
switch($day_of_week){
case "Mon": $blank = 0; break;
case "Wed": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Thu": $blank = 3; break;
case "Fri": $blank = 4; break;
case "Sat": $blank = 5; break;
case "Son": $blank = 6; break;
}
//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year);
//Here we start building the table heads
echo "<table border=0 width=100%>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=42 align=center>Mo</td><td width=42 align=center>Di</td><td width=42 align=center>Mi</td><td width=42 align=center>Do</td><td width=42 align=center>Fr</td><td width=42 align=center>Sa</td><td width=42 align=center>So</td></tr>";
//This counts the days in the week, up to 7
$day_count = 1;
echo "<tr>";
//first we take care of those blank days
while
( $blank > 0 )
{
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
//sets the first day of the month to 1
$day_num = 1;
//count up the days, untill we've done all of them in the month
while
( $day_num <= $days_in_month )
{
if ($day_num == date('d', $date))
{
echo "<td align=center><b>$day_num</b> </td>";
}
else
{
echo "<td align=center> $day_num </td>";
}
$day_num++;
$day_count++;
//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}
//Finaly we finish out the table with some blanks if needed
while
( $day_count >1 && $day_count <=7 )
{
echo "<td> </td>";
$day_count++;
}
echo "</tr></table>";