IntlDateFormatter::format
To do the conversion in respect of a specific locale, you can use the IntlDateFormatter class:
function getMonthName ($locale, $monthNumber) {
$formatter = new IntlDateFormatter($locale);
$formatter->setPattern('MMMM');
return $formatter->format(mktime(0, 0, 0, $monthNumber));
}
$monthName = getMonthName('fr_FR', 8); // août
This requires the intl extension. The class is available in PHP 5.3.0+.
Historical - before PHP 8.1.0
Before the IntlDateFormatter class, the strftime function was used. This function has been deprecated in PHP 8.1.0.
To do the conversion in respect of the current locale, you can use the strftime function:
setlocale(LC_TIME, 'fr_FR.UTF-8');
$monthName = strftime('%B', mktime(0, 0, 0, $monthNumber));
date doesn't respect the locale, strftime does.