1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| <?php
ini_set("display_errors", TRUE);
error_reporting(E_ALL);
$num_year = date('Y'); // N° année en cours = 2021
// Inspiré aussi de :
// https://www.php.net/manual/fr/function.easter-days.php
$holidays = array(
// Jour de l'an
mktime(0, 0, 0, 01, 01, $num_year),
// 1er mai
mktime(0, 0, 0, 05, 01, $num_year),
//##################################
// pour TEST sur 3 mai
mktime(0, 0, 0, 05, 03, $num_year),
// pour TEST sur 4 mai
mktime(0, 0, 0, 05, 04, $num_year),
//##################################
// 14 juillet
mktime(0, 0, 0, 07, 14, $num_year)
);
/*
EXEMPLE RECHERCHE POUR DÉMO :
01/01/2021
01/05/2021
03/05/2021
05/05/2021
14/07/2021
foreach ($holidays as $holiday)
{
echo date("d/m/Y", $holiday) . '<br>';
}
*/
// https://www.developpez.net/forums/d2100110-nouveau/php/langage/modification-amelioration-boucles-for/
// Merci aussi à "Très-Douée" pour son idée ;-)
setlocale(LC_TIME, 'fr_FR.UTF-8', 'fr_FR', 'fr', 'fra_fra'); // pour avoir le nom des jours en français
$color = array('rgb(51, 102, 255)', 'Red', 'Lavender', 'yellow', 'green', 'black', 'purple', 'pink', 'navy');
$num_mois = 5 ; // numéro du mois à afficher
$nb_jour = date('j',mktime(0,0,0,$num_mois +1,0,$num_year)); // nombre de jours du mois à afficher
echo '
<table border=1><caption><b>'.strtoupper (strftime("%B %Y", mktime(12,0,0,$num_mois,1,$num_year))).'</b></caption>';
for ($i = 1; $i <= $nb_jour; $i++)
{
$stamp = mktime(12, 0, 0, $num_mois, $i, $num_year);
$we = date('N', $stamp); // 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1 2 3 4 5 6 7 1
//$jours_feries = '01/05/2021'; // en dur pour test
foreach ($holidays as $holiday)
{
$jours_feries = date("d/m/Y", $holiday);
$date_boucle_mois = date("d/m/Y", $stamp);
if ($date_boucle_mois == $jours_feries)
{
$we = 8;
}
}
echo '
<tr>
<td width="30" bgcolor = "'.$color[2].'">'.$i.'</td>
<td width="80" bgcolor = "'.$color[2].'">'. ucwords(strftime("%A", $stamp)). '</td>
<td width="1080" bgcolor = '.$color[$we].'> '.date("d/m/Y", $stamp).' </td>
</tr>
';
}
echo '
</table>';
?> |
Partager