String Functions

PHP localeconv() Function

Topic: PHP String ReferencePrev|Next

Description

The localeconv() function returns an associative array containing localized numeric and monetary formatting information. The returned array contains the following elements:

Array element Description
decimal_point Decimal point character
thousands_sep Separator character for thousands
int_curr_symbol International currency symbol (e.g., USD)
currency_symbol Local currency symbol (e.g., $)
mon_decimal_point Monetary decimal point character
mon_thousands_sep Monetary thousands separator
positive_sign Sign for positive values (e.g., +)
negative_sign Sign for negative values (e.g., -)
int_frac_digits International fractional digits
frac_digits Local fractional digits
p_cs_precedes true (1) if currency symbol comes before a positive value,
false (0) if it comes after the value
p_sep_by_space true (1) if there is a spaces between the currency symbol and a positive value,
false (0) otherwise
n_cs_precedes true (1) if currency symbol comes before a negative value,
false (0) if it comes after the value
n_sep_by_space true (1) if there is a spaces between the currency symbol and a negative value,
false (0) otherwise
p_sign_posn
  • 0 - The quantity and currency symbol surrounded by parentheses
  • 1 - The positive sign comes before the quantity and currency symbol
  • 2 - The positive sign comes after the quantity and currency symbol
  • 3 - The positive sign comes immediately before the currency symbol
  • 4 - The positive sign comes immediately after the currency symbol
n_sign_posn
  • 0 - The quantity and currency symbol surrounded by parentheses
  • 1 - The negative sign comes before the quantity and currency symbol
  • 2 - The negative sign comes after the quantity and currency symbol
  • 3 - The negative sign comes immediately before the currency symbol
  • 4 - The negative sign comes immediately after the currency symbol
grouping Array containing numeric groupings (e.g., 2 indicates 1 00 00 00)
mon_grouping Array containing monetary groupings (e.g., 3 indicates 1 000 000)

Tip: The grouping and mon_grouping fields indicates how digits in numbers and currency values should be grouped and separated by the thousands separator character. Also, see the setlocale() function reference to understand how to define locale settings.

The following table summarizes the technical details of this function.

Return Value: Returns data based upon the current locale as set by setlocale().
Version: PHP 4.0.5+

Syntax

The basic syntax of the localeconv() function is given with:

localeconv();

The following example shows the localeconv() function in action.

<?php
// Getting the United States locale numeric formatting information
if(false !== setlocale(LC_ALL, "en_US")){
    $locale_info = localeconv();
    print_r($locale_info);
}
?>

The output of the above example will look something like this:

Array ( [decimal_point] => . [thousands_sep] => , [int_curr_symbol] => USD [currency_symbol] => $ [mon_decimal_point] => . [mon_thousands_sep] => , [positive_sign] => [negative_sign] => - [int_frac_digits] => 2 [frac_digits] => 2 [p_cs_precedes] => 1 [p_sep_by_space] => 0 [n_cs_precedes] => 1 [n_sep_by_space] => 0 [p_sign_posn] => 3 [n_sign_posn] => 0 [grouping] => Array ( [0] => 3 ) [mon_grouping] => Array ( [0] => 3 ) )

Parameters

The localeconv() function doesn't have any parameters.

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties