PHP nl_langinfo() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

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.

PHP
$day = nl_langinfo(DAY_1);
CallWhat 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
PHP
nl_langinfo(int $item): string|false

Parameters

ParameterDescription
itemRequired. One of the locale constants, such as DAY_1 or RADIXCHAR.

Return Value

Return ValueDescription
stringThe locale value for the item.
falseReturned when the item is not valid.

PHP Examples

Example 1 — Get a Day and Month Name

Use the C locale so the output is the same on every system.

PHP
<?php
setlocale(LC_ALL, "C");

echo nl_langinfo(DAY_1), PHP_EOL;
echo nl_langinfo(MON_1), PHP_EOL;

How It Works

  1. Set the locale. The C locale uses English names.
  2. Ask for DAY_1. The first day is Sunday.
  3. Ask for MON_1. The first month is January.
  4. 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
<?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

  1. Check support first. Windows has no nl_langinfo.
  2. Exit early. return stops the script if it is missing.
  3. Read RADIXCHAR. The decimal point is a dot.
  4. Read THOUSEP. It is empty in the C locale.

Example 3 — List All Weekday Names

Loop over the DAY constants to build a full list.

PHP
<?php
setlocale(LC_ALL, "C");

$days = [];
for ($i = 1; $i <= 7; $i++) {
    $days[] = nl_langinfo(constant("DAY_" . $i));
}

echo implode(", ", $days), PHP_EOL;

How It Works

  1. Loop from 1 to 7. Each number matches one DAY constant.
  2. Build the name. constant("DAY_1") looks up the constant by name.
  3. Collect each result. They go into the $days array.
  4. Join them. implode makes one readable line.

Frequently Asked Questions

nl_langinfo() returns locale-specific information such as day names, month names, the decimal point, or the character set, based on the current locale.
string|false nl_langinfo(int $item). The item is one of the locale constants like DAY_1 or RADIXCHAR.
No. It is only available on systems that support the C library nl_langinfo(), such as Linux and macOS. Use function_exists() to check.
Call setlocale() first with a locale that is installed on the server, such as "fr_FR.UTF-8".
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

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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