File "tableau_03.php"
Full Path: /home/analogde/www/New folder/tableau_03.php
File size: 1.51 KB
MIME-type: text/html
Charset: utf-8
<style>
table {
border-collapse: collapse;
width: 100%;
}
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"];
// Afficher l'en-tĂȘte avec les jours de la semaine
echo "<table class='calendar'>";
echo "<tr>";
foreach ($headings as $heading) {
echo "<td class='day'>$heading</td>";
}
echo "</tr>";
// Afficher toutes les dates des 12 mois dans une seule ligne
echo "<tr>";
for ($month = 1; $month <= 12; $month++) {
$thisMonth = new DateTime("$year-$month-01");
$daysInMonth = $thisMonth->format("t");
// Afficher les dates du mois
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 tous les mois s'affichent sur une seule ligne
$remainingDays = (7 - ($daysInMonth % 7)) % 7;
for ($i = 0; $i < $remainingDays; $i++) {
echo "<td class='day'></td>";
}
echo "</tr>";
echo "</table>";
?>