Home PHP String Functions nl_langinfo() PHP nl_langinfo() Function Definition In PHP, nl_langinfo() returns language and locale details for a given item, such as day names or the decimal point.
It reads from the current locale set by setlocale(). It is not available on Windows.
Syntax Call nl_langinfo() with the values you need. Start with this line.
$day = nl_langinfo(DAY_1); Call What it does nl_langinfo(DAY_1)Returns the name of the first day, "Sunday" in the C locale. nl_langinfo(MON_1)Returns "January" in the C locale. nl_langinfo(RADIXCHAR)Returns the decimal point character.
Constants include DAY_1 to DAY_7, ABDAY_1 to ABDAY_7, MON_1 to MON_12, ABMON_1 to ABMON_12, RADIXCHAR, THOUSEP, and CODESET.
Library declarations nl_langinfo(int $item): string|false Parameters Parameter Description item Required. One of the locale constants, such as DAY_1 or RADIXCHAR.
Return Value Return Value Description string The locale value for the item. false Returned when the item is not valid.
PHP Examples 1. Get a Day and Month Name 2. Guard for Missing Support 3. List All Weekday Names Example 1 — Get a Day and Month Name Use the C locale so the output is the same on every system.
<?php
setlocale(LC_ALL, "C");
echo nl_langinfo(DAY_1), PHP_EOL;
echo nl_langinfo(MON_1), PHP_EOL; How It Works Set the locale. The C locale uses English names.Ask for DAY_1. The first day is Sunday.Ask for MON_1. The first month is January.Switch locales. A different locale returns names in that language.Example 2 — Guard for Missing Support Check that the function exists before using it, then read the number separators.
<?php
if (!function_exists("nl_langinfo")) {
echo "nl_langinfo() is not available here", PHP_EOL;
return;
}
setlocale(LC_ALL, "C");
echo "Radix: " . nl_langinfo(RADIXCHAR), PHP_EOL;
echo "Thousands: '" . nl_langinfo(THOUSEP) . "'", PHP_EOL; How It Works Check support first. Windows has no nl_langinfo.Exit early. return stops the script if it is missing.Read RADIXCHAR. The decimal point is a dot.Read THOUSEP. It is empty in the C locale.Frequently Asked Questions What does PHP nl_langinfo() do? nl_langinfo() returns locale-specific information such as day names, month names, the decimal point, or the character set, based on the current locale.
What is the syntax for nl_langinfo()? string|false nl_langinfo(int $item). The item is one of the locale constants like DAY_1 or RADIXCHAR.
Does nl_langinfo() work on Windows? No. It is only available on systems that support the C library nl_langinfo(), such as Linux and macOS. Use function_exists() to check.
How do I change the language of the results? Call setlocale() first with a locale that is installed on the server, such as "fr_FR.UTF-8".
What does it return for an invalid item? It returns false and raises a warning.
Next: nl2br() nl2br() inserts an HTML line break tag before every newline in a string.
nl2br() tutorial → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion