Você está na página 1de 2

<!

DOCTYPE html>
<html>
<head>
<title>Calendário do mês</title>
<meta charset="UTF-8">
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: center;
}
</style>
</head>
<body>
<h1>Calendário do mês</h1>
<table>
<thead>
<tr>
<th>Domingo</th>
<th>Segunda</th>
<th>Terça</th>
<th>Quarta</th>
<th>Quinta</th>
<th>Sexta</th>
<th>Sábado</th>
</tr>
</thead>
<tbody>
<tr>
<!-- Primeira linha da tabela -->
<?php
// Definir a data inicial como o primeiro dia do mês
atual
$data = new DateTime('first day of this month');
// Iterar pelos dias do mês
for ($i = 1; $i <= $data->format('t'); $i++) {
// Adicionar uma nova coluna para cada dia
if ($i == 1) {
// Adicionar as células vazias para os
dias anteriores ao primeiro dia do mês
for ($j = 0; $j < $data->format('w'); $j+
+) {
echo '<td></td>';
}
}
// Adicionar o dia na célula correspondente
echo '<td>' . $i . '</td>';
// Adicionar uma nova linha após o último dia
da semana
if (($data->format('w') == 6) && ($i != $data-
>format('t'))) {
echo '</tr><tr>';
}
// Avançar para o próximo dia
$data->modify('+1 day');
}
// Adicionar as células vazias para os dias após o
último dia do mês
if ($data->format('w') != 0) {
for ($j = $data->format('w'); $j < 7; $j++) {
echo '<td></td>';
}
}
?>
</tr>
</tbody>
</table>
</body>
</html>

Você também pode gostar