File "tableau_02.php"
Full Path: /home/analogde/www/New folder/tableau_02.php
File size: 1.64 KB
MIME-type: text/html
Charset: utf-8
<style>
table {
border-collapse: collapse;
}
td {
border: 1px solid #111;
padding: 5px;
text-align: center;
}
.monthName {
width: 15ch;
}
.day {
width: 2.5ch;
}
.day:nth-child(7n), .day:nth-child(7n+1) {
background: #aaa;
}
.day.highlightYellow {
background: #ff6;
}
.day.highlightGreen {
background: #2f7;
}
</style>
<?php
$year = 2025;
$headings = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
echo "<table class='calendar'>";
echo "<tr><td><b>Months</b></td>";
// En-têtes des jours de la semaine
foreach ($headings as $heading) {
echo "<td class='day'>$heading</td>";
}
echo "</tr>";
// Cycle à travers les mois
for ($month = 1; $month <= 12; $month++) {
$thisMonth = new DateTime("$year-$month-01");
$daysInMonth = $thisMonth->format("t");
$monthName = $thisMonth->format("F");
echo "<tr class='month'><td class='monthName'>$monthName</td>";
// Afficher tous les jours du mois dans la même ligne
for ($day = 1; $day <= $daysInMonth; $day++) {
$rand = mt_rand(1, 100);
$highlightClass = (!($rand % 15) ? "highlightYellow" : (!($rand % 35) ? "highlightGreen" : ""));
echo "<td class='day $highlightClass'>$day</td>";
}
// Compléter la ligne pour que chaque mois ait 7 colonnes (7 jours)
$remainingDays = 7 - ($daysInMonth % 7);
for ($i = 0; $i < $remainingDays && $remainingDays < 7; $i++) {
echo "<td class='day'></td>";
}
echo "</tr>";
}
echo "</table>";
?>