This question asks how to get a list of months, I only see hints, not a complete code answer so:
If you have IntlDateFormatter
available - which is available in most of the cases, you can create a formatter in a given locale and repeatedly push a date to it created just based on month number
// or any other locales like pl_PL, cs_CZ, fr_FR, zh, zh_Hans, ...
$locale = 'en_GB';
$dateFormatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::LONG, // date type
IntlDateFormatter::NONE // time type
);
$dateFormatter->setPattern('LLLL'); // full month name with NO DECLENSION ;-)
$months_locale = [];
for ($month_number = 1; $month_number <= 12; ++$month_number) {
$months_locale[] = $dateFormatter->format(
// 'n' => month number with no leading zeros
DateTime::createFromFormat('n', (string)$month_number)
);
}
// test output
echo "<pre>";
var_dump($months_locale);
echo "</pre>";
Note: LLLL
takes care of not-declining, but it does not take care of the lowercase/uppercase of the first letter if the languages has such things.
Good example is that you can get January
for en_GB
but leden
for cs_CZ
If you want all letters lowercase => use mb_strtolower($month_name);
- docs
If you want just the FIRST letter to be upper case =>
=> use mb_convert_case($month_name, MB_CASE_TITLE, 'UTF-8');
- docs
Always use mb_*
functions or their variations for locale-originating strings !
So no, don't use ucfirst
!
strftime
, and install the proper locale, & set your current locale to serbian. – Sonnier