Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP String nl_langinfo() Function



The PHP String nl_langinfo() function is used to retrieve entries from a given locale category. Unlike localeconv(), which returns all elements, nl_langinfo() allows you to select a particular element.

The nl_langinfo() method is not implemented on the Windows platform, which is an important point to note.

Syntax

Below is the syntax of the PHP String nl_langinfo() function −

string nl_langinfo ( int $item )

Parameters

This function accepts $item parameter which specifies what element to return. Should be any of the following elements −

Time and Calendar −

  • ABDAY_(1-7): Abbreviated name of the numbered day of the week

  • ABDAY_(1-7): Abbreviated name of the numbered day of the week

  • DAY_(1-7): Name of the numbered day of the week (DAY_1 = Sunday)

  • ABMON_(1-12): Abbreviated name of the numbered month of the year

  • MON_(1-12): Name of the numbered month of the year

  • AM_STR: String for Ante meridian

  • PM_STR: String for Post meridian

  • D_T_FMT: String that can be used as the format string for strftime() to represent time and date

  • D_FMT: String that can be used as the format string for strftime() to represent date

  • T_FMT: String that can be used as the format string for strftime() to represent time

  • T_FMT_AMPM: String that can be used as the format string for strftime() to represent time in 12-hour format with ante/post meridian

  • ERA: Alternate era

  • ERA_YEAR: Year in alternate era format

  • ERA_D_T_FMT: Date and time in alternate era format (string can be used in strftime())

  • ERA_D_FMT: Date in alternate era format (string can be used in strftime())

  • ERA_T_FMT: Time in alternate era format (string can be used in strftime())

Monetary Category −

  • INT_CURR_SYMBOL: Currency symbol (example: USD)

  • CURRENCY_SYMBOL: Currency symbol (example: $)

  • CRNCYSTR: Same as CURRENCY_SYMBOL

  • MON_DECIMAL_POINT: Monetary decimal point character

  • MON_THOUSANDS_SEP: Monetary thousands separator

  • POSITIVE_SIGN: Positive value character

  • NEGATIVE_SIGN: Negative value character

  • MON_GROUPING: Array displaying how monetary numbers are grouped (example: 1 000 000)

  • INT_FRAC_DIGITS: International fractional digits

  • FRAC_DIGITS: Local fractional digits

  • P_CS_PRECEDES: True (1) if currency symbol is placed in front of a positive value, False (0) if it is placed behind

  • P_SEP_BY_SPACE: True (1) if there is a space between the currency symbol and a positive value, False (0) otherwise

  • N_CS_PRECEDES: True (1) if currency symbol is placed in front of a negative value, False (0) if it is placed behind

  • N_SEP_BY_SPACE: True (1) if there is a space between the currency symbol and a negative value, False (0) otherwise

Numeric Category −

  • DECIMAL_POINT: Decimal point character

  • RADIXCHAR: Same as DECIMAL_POINT

  • THOUSANDS_SEP: Separator character for thousands

  • THOUSEP: Same as THOUSANDS_SEP

  • GROUPING: Array displaying how numbers are grouped

Return Value

The nl_langinfo() function returns specific information on SUCCESS, else FALSE on failure.

PHP Version

First introduced in core PHP 4.1.0, the nl_langinfo() function continues to function easily in PHP 5, PHP 7, and PHP 8.

Example 1

First we will show you the basic example of the PHP String nl_langinfo() function to retrieve the name of the current locale's abbreviated weekday.

<?php
   // Set the locale to US English
   setlocale(LC_TIME, "en_US");

   // Get the abbreviated weekday name
   echo "Abbreviated Weekday Name: " . nl_langinfo(ABDAY_1);
?>

Output

Here is the outcome of the following code −

Abbreviated Weekday Name: Sun

Example 2

In the below PHP code we will try to use the nl_langinfo() function to retrieve the currency symbol for the current locale.

<?php
   // Set the locale to US English
   setlocale(LC_MONETARY, "en_US");
   
   // Get the currency symbol
   echo "Currency Symbol: " . nl_langinfo(CRNCYSTR);
?> 

Output

This will generate the below output −

Currency Symbol: $

Example 3

Now in the below code we are using nl_langinfo() function to get the full name of a month as per the locale setting.

<?php
   // Set the locale to French
   setlocale(LC_TIME, "fr_FR");

   // Get the full name of the first month
   echo "Full Month Name (January): " . nl_langinfo(MON_1);
?> 

Output

This will create the below output −

Full Month Name (January): janvier

Example 4

In the following example, the function nl_langinfo() retrieves and displays multiple locale information items (weekday, month, and currency) based on the current locale.

<?php
   // Set the locale to German
   setlocale(LC_ALL, "de_DE");

   // Retrieve and display various locale information
   echo "Abbreviated Weekday Name: " . nl_langinfo(ABDAY_2) . "\n";
   echo "Full Month Name (February): " . nl_langinfo(MON_2) . "\n";
   echo "Currency Symbol: " . nl_langinfo(CRNCYSTR) . "\n";
?> 

Output

Following is the output of the above code −

Abbreviated Weekday Name: Mo
Full Month Name (February): Februar
Currency Symbol: -Eu
php_function_reference.htm
Advertisements