I was wondering if it was posible to display the month in a calender in french ?
$daysOfWeek = array(' Lundi ',' Mardi ','Mercredi',' Jeudi ','Vendredi',' Samedi ');
$firstDayOfMonth = mktime(0,0,0,$month,1,$year);
$numberDays = date('t',$firstDayOfMonth);
$dateComponents = getdate($firstDayOfMonth);
$monthName = $dateComponents['month'];
$dayOfWeek = $dateComponents['wday'];
if($dayOfWeek==0){
$dayOfWeek = 6;
}else{
$dayOfWeek = $dayOfWeek-1;
}
$datetoday = date('Y-m-d');
$calendar = "<table>";
$calendar .= "<h2>$monthName $year</h2>";
CodePudding user response:
If you could use the PECL intl module
$date = new DateTime(); $formatter = new IntlDateFormatter('fr_FR'); $dateFormatter = \IntlDateFormatter::create( \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, 'EEEE MMMM' ); var_dump($dateFormatter->format($date)); // string(13) "lundi janvier"Else, with a simple array and
date('n')anddate('N'). See DateTime::format() for formats.$days = ['Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche']; $months = ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre']; $timestamp = 1643660449; // Example. Should be your mktime() $monthName = $months[date('n', $timestamp) - 1]; $dayName = $days[date('N', $timestamp) - 1]; echo "$dayName $monthName"; // Lundi JanvierFinally, note that strftime() allows to format a date, but is now deprecated.
Some additional notes:
- Don't use
in your array, but only when displaying your string (maybe take a look to margins/padding using CSS) - The
<h2>tag cannot be the first child of a<table>tag.
