Вы можете использовать следующий шаблон HTML вместе с приведенным ниже кодом PHP - не самое элегантное решение, но должно быть достаточно простым для понимания новичком ie:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
<style type="text/css">
th.br_bot
{
border-bottom: 1px solid black;
padding: 2px;
}
th.br_btr
{
border-bottom: 1px solid black;
border-right: 1px solid black;
padding: 2px;
}
td.week_num
{
font-size: 9pt;
border-bottom: 1px solid black;
border-right: 1px solid black;
background-color: #D0D0D0;
padding: 2px;
}
td.day
{
font-size: 9pt;
border-bottom: 1px solid black;
border-right: 1px solid black;
}
td.day_red
{
font-size: 9pt;
border-bottom: 1px solid black;
border-right: 1px solid black;
background-color: #EFC2C3;
}
td.day_blue
{
font-size: 9pt;
border-bottom: 1px solid black;
border-right: 1px solid black;
background-color: #B6CBEF;
}
span.week_day
{
color: black;
}
span.week_end
{
color: red;
}
</style>
</head>
<body>
<table id="cal" cellspacing="0" cellpadding="0" style="border-left:1px solid black; border-top:1px solid black;font-weight:bold;">
<tr style="font-size:9pt;" bgcolor="#D6B695">
<th colspan="8" class="br_btr"> JANUARY </th>
<th colspan="8" class="br_btr"> FEBRUARY </th>
<th colspan="8" class="br_btr"> MARCH </th>
<th colspan="8" class="br_btr"> APRIL </th>
</tr>
<tr>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
</tr>
<tr><td>{SECTION_1}</td></tr>
<tr style="font-size:9pt;" bgcolor="#D6B695">
<th colspan="8" class="br_btr"> MAY </th>
<th colspan="8" class="br_btr"> JUNE </th>
<th colspan="8" class="br_btr"> JULY </th>
<th colspan="8" class="br_btr"> AUGUST </th>
</tr>
<tr>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
</tr>
<tr><td>{SECTION_2}</td></tr>
<tr style="font-size:9pt;" bgcolor="#D6B695">
<th colspan="8" class="br_btr"> SEPTEMBER </th>
<th colspan="8" class="br_btr"> OCTOBER </th>
<th colspan="8" class="br_btr"> NOVEMBER </th>
<th colspan="8" class="br_btr"> DECEMBER </th>
</tr>
<tr>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
<th class="br_bot"> </th>
<th class="br_bot">M</th>
<th class="br_bot">T</th>
<th class="br_bot">W</th>
<th class="br_bot">T</th>
<th class="br_bot">F</th>
<th class="br_bot">S</th>
<th class="br_btr">S</th>
</tr>
<tr><td>{SECTION_3}</td></tr>
</table>
</body>
</html>
<?php
// returns HTML for the given month
function month_calendar($year,$month)
{
$my_time = mktime(0,0,0,$month,1,$year); // Unix timestamp for the beginning of the month
$start_day = date('N', $my_time);
$start_week = (int)date('W',$my_time); // because date returns zero-padded value
$daysInMonth = date('t',$my_time); // how many days in the given month
$dayNumber = date('z',$my_time) + 1; // day of the year for the 1st date of the month (0 - 365)
$output = Array();
// show first week
$current_week = '<td align="center" class="week_num">'.($start_week++).'</td>';
if($start_week > 52) $start_week = 1;
$dayOfWeek = 1;
while($dayOfWeek < $start_day)
{
// show empty cells until we reach the start of the month
$current_week .= '<td class="day"> </td>';
$dayOfWeek++;
}
$dayOfMonth = 1;
while($dayOfWeek <= 7)
{
$current_week .= '<td class="day"><span class="week_'.($dayOfWeek > 5 ? 'end' : 'day').'" style="padding:2px">'.($dayOfMonth++).'</span></td>';
$dayOfWeek++;
$dayNumber++;
}
$output[] = $current_week;
while($dayOfMonth <= $daysInMonth)
{
$current_week = '<td align="center" class="week_num">'.($start_week++).'</td>';
if($start_week > 52) $start_week = 1;
$dayOfWeek = 1;
while($dayOfWeek <= 7)
{
if($dayOfMonth <= $daysInMonth) $current_week .= '<td class="day"><span class="week_'.($dayOfWeek > 5 ? 'end' : 'day').'" style="padding:2px">'.($dayOfMonth++).'</span></td>';
else $current_week .= '<td class="day"> </td>'; // show empty cells after the end of the month
$dayOfWeek++;
$dayNumber++;
}
$output[] = $current_week;
}
return $output;
}
// returns HTML for 4 months - starting at the given month/year
function section($year,$month)
{
$month_1 = month_calendar($year, $month);
$month_2 = month_calendar($year, $month + 1);
$month_3 = month_calendar($year, $month + 2);
$month_4 = month_calendar($year, $month + 3);
$max_weeks = max(
count($month_1),
count($month_2),
count($month_3),
count($month_4)
);
$empty_week = '';
for($i = 1; $i <= 8; $i++) // 7 days + a cell for the week number
$empty_week .= '<td class="day"> </td>';
$output = '';
for($i = 0; $i < $max_weeks; $i++)
{
$output .= '<tr>';
$output .= $month_1[$i] != '' ? $month_1[$i] : $empty_week;
$output .= $month_2[$i] != '' ? $month_2[$i] : $empty_week;
$output .= $month_3[$i] != '' ? $month_3[$i] : $empty_week;
$output .= $month_4[$i] != '' ? $month_4[$i] : $empty_week;
$output .= '</tr>';
}
return $output;
}
if($template = @file_get_contents('/tempates/calendar.html'))
{
// show calendar
$cal_year = 2020;
$template = str_replace('<tr><td>{SECTION_1}</td></tr>',section($cal_year,1),$template);
$template = str_replace('<tr><td>{SECTION_2}</td></tr>',section($cal_year,5),$template);
$template = str_replace('<tr><td>{SECTION_3}</td></tr>',section($cal_year,9),$template);
echo $template;
}
else die('Could not find template - calendar.html');
?>