
- PHP - Home
- PHP - Roadmap
- PHP - Introduction
- PHP - Installation
- PHP - History
- PHP - Features
- PHP - Syntax
- PHP - Hello World
- PHP - Comments
- PHP - Variables
- PHP - Echo/Print
- PHP - var_dump
- PHP - $ and $$ Variables
- PHP - Constants
- PHP - Magic Constants
- PHP - Data Types
- PHP - Type Casting
- PHP - Type Juggling
- PHP - Strings
- PHP - Boolean
- PHP - Integers
- PHP - Files & I/O
- PHP - Maths Functions
- PHP - Heredoc & Nowdoc
- PHP - Compound Types
- PHP - File Include
- PHP - Date & Time
- PHP - Scalar Type Declarations
- PHP - Return Type Declarations
- PHP - Operators
- PHP - Arithmetic Operators
- PHP - Comparison Operators
- PHP - Logical Operators
- PHP - Assignment Operators
- PHP - String Operators
- PHP - Array Operators
- PHP - Conditional Operators
- PHP - Spread Operator
- PHP - Null Coalescing Operator
- PHP - Spaceship Operator
- PHP Control Statements
- PHP - Decision Making
- PHP - If…Else Statement
- PHP - Switch Statement
- PHP - Loop Types
- PHP - For Loop
- PHP - Foreach Loop
- PHP - While Loop
- PHP - Do…While Loop
- PHP - Break Statement
- PHP - Continue Statement
- PHP Arrays
- PHP - Arrays
- PHP - Indexed Array
- PHP - Associative Array
- PHP - Multidimensional Array
- PHP - Array Functions
- PHP - Constant Arrays
- PHP Functions
- PHP - Functions
- PHP - Function Parameters
- PHP - Call by value
- PHP - Call by Reference
- PHP - Default Arguments
- PHP - Named Arguments
- PHP - Variable Arguments
- PHP - Returning Values
- PHP - Passing Functions
- PHP - Recursive Functions
- PHP - Type Hints
- PHP - Variable Scope
- PHP - Strict Typing
- PHP - Anonymous Functions
- PHP - Arrow Functions
- PHP - Variable Functions
- PHP - Local Variables
- PHP - Global Variables
- PHP Superglobals
- PHP - Superglobals
- PHP - $GLOBALS
- PHP - $_SERVER
- PHP - $_REQUEST
- PHP - $_POST
- PHP - $_GET
- PHP - $_FILES
- PHP - $_ENV
- PHP - $_COOKIE
- PHP - $_SESSION
- PHP File Handling
- PHP - File Handling
- PHP - Open File
- PHP - Read File
- PHP - Write File
- PHP - File Existence
- PHP - Download File
- PHP - Copy File
- PHP - Append File
- PHP - Delete File
- PHP - Handle CSV File
- PHP - File Permissions
- PHP - Create Directory
- PHP - Listing Files
- Object Oriented PHP
- PHP - Object Oriented Programming
- PHP - Classes and Objects
- PHP - Constructor and Destructor
- PHP - Access Modifiers
- PHP - Inheritance
- PHP - Class Constants
- PHP - Abstract Classes
- PHP - Interfaces
- PHP - Traits
- PHP - Static Methods
- PHP - Static Properties
- PHP - Namespaces
- PHP - Object Iteration
- PHP - Encapsulation
- PHP - Final Keyword
- PHP - Overloading
- PHP - Cloning Objects
- PHP - Anonymous Classes
- PHP Web Development
- PHP - Web Concepts
- PHP - Form Handling
- PHP - Form Validation
- PHP - Form Email/URL
- PHP - Complete Form
- PHP - File Inclusion
- PHP - GET & POST
- PHP - File Uploading
- PHP - Cookies
- PHP - Sessions
- PHP - Session Options
- PHP - Sending Emails
- PHP - Sanitize Input
- PHP - Post-Redirect-Get (PRG)
- PHP - Flash Messages
- PHP AJAX
- PHP - AJAX Introduction
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML
- PHP - XML Introduction
- PHP - Simple XML Parser
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Login Example
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP Advanced
- PHP - MySQL
- PHP.INI File Configuration
- PHP - Array Destructuring
- PHP - Coding Standard
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Try…Catch
- PHP - Bugs Debugging
- PHP - For C Developers
- PHP - For PERL Developers
- PHP - Frameworks
- PHP - Core PHP vs Frame Works
- PHP - Design Patterns
- PHP - Filters
- PHP - JSON
- PHP - Exceptions
- PHP - Special Types
- PHP - Hashing
- PHP - Encryption
- PHP - is_null() Function
- PHP - System Calls
- PHP - HTTP Authentication
- PHP - Swapping Variables
- PHP - Closure::call()
- PHP - Filtered unserialize()
- PHP - IntlChar
- PHP - CSPRNG
- PHP - Expectations
- PHP - Use Statement
- PHP - Integer Division
- PHP - Deprecated Features
- PHP - Removed Extensions & SAPIs
- PHP - PEAR
- PHP - CSRF
- PHP - FastCGI Process
- PHP - PDO Extension
- PHP - Built-In Functions
PHP String localeconv() Function
The PHP String localeconv() function is used to get numeric formatting information. This function returns an array with local numeric and monetary formatting information. Since this method is non-parameterized, we do not have to provide anything.
Syntax
Below is the syntax of the PHP String localeconv() function −
array localeconv ( void )
Parameters
This function does not accepts any parameter.
Return Value
The localeconv() function returns data based upon the current locale as set by setlocale().
Array Elements
The returned array contains the following fields −
Array Element | Description |
---|---|
decimal_point | It is the decimal point character |
thousands_sep | It is the thousands separator |
grouping | It is an array containing numeric groupings |
int_curr_symbol | It is an international currency symbol (i.e. USD) |
currency_symbol | It is a local currency symbol (i.e. $) |
mon_decimal_point | It is the monetary decimal point character |
mon_thousands_sep | It is the monetary thousands separator |
mon_grouping | It is an array containing monetary groupings |
positive_sign | It is the sign for positive values |
negative_sign | It is the sign for negative values |
int_frac_digits | It is an international fractional digits |
frac_digits | It is the local fractional digits |
p_cs_precedes | It is true if currency_symbol precedes a positive value, false if it succeeds one |
p_sep_by_space | It is true if a space separates currency_symbol from a positive value, false otherwise |
n_cs_precedes | It is true if currency_symbol precedes a negative value, false if it succeeds one |
n_sep_by_space | It is true if a space separates currency_symbol from a negative value, false otherwise |
p_sign_posn |
0 - Parentheses surround the quantity and currency_symbol 1 - The sign string precedes the quantity and currency_symbol 2 - The sign string succeeds the quantity and currency_symbol 3 - The sign string immediately precedes the currency_symbol 4 - The sign string immediately succeeds the currency_symbol |
n_sign_posn |
0 - Parentheses surround the quantity and currency_symbol 1 - The sign string precedes the quantity and currency_symbol 2 - The sign string succeeds the quantity and currency_symbol 3 - The sign string immediately precedes the currency_symbol 4 - The sign string immediately succeeds the currency_symbol |
PHP Version
First introduced in core PHP 4.0.5, the localeconv() 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 localeconv() function to show the default locale information, if there is no locale is set explicitly.
<?php // Retrieve locale-specific information $locale_info = localeconv(); // Display the array with default locale information print_r($locale_info); ?>
Output
This will generate the below output −
Array ( [decimal_point] => . [thousands_sep] => [int_curr_symbol] => [currency_symbol] => [mon_decimal_point] => [mon_thousands_sep] => [positive_sign] => [negative_sign] => [int_frac_digits] => 127 [frac_digits] => 127 [p_cs_precedes] => 127 [p_sep_by_space] => 127 [n_cs_precedes] => 127 [n_sep_by_space] => 127 [p_sign_posn] => 127 [n_sign_posn] => 127 [grouping] => Array ( ) [mon_grouping] => Array ( ) )
Example 2
Here we will show you how the localeconv() function is used to set the locale for the script to "US" and retrieves locale specific information.
<?php // Set the locale to United States setlocale(LC_ALL,"US"); // Retrieve locale-specific information $locale_info = localeconv(); // Print the array containing locale-specific details print_r($locale_info); ?>
Output
Here is the outcome of the following code −
Array ( [decimal_point] => . [thousands_sep] => [int_curr_symbol] => [currency_symbol] => [mon_decimal_point] => [mon_thousands_sep] => [positive_sign] => [negative_sign] => [int_frac_digits] => 127 [frac_digits] => 127 [p_cs_precedes] => 127 [p_sep_by_space] => 127 [n_cs_precedes] => 127 [n_sep_by_space] => 127 [p_sign_posn] => 127 [n_sign_posn] => 127 [grouping] => Array ( ) [mon_grouping] => Array ( ) )
Example 3
Now the below code illustrates the formatting differences between the French (fr_FR) and US (en_US) locale settings with the help of localeconv() function.
<?php // Set and retrieve US locale setlocale(LC_ALL, "en_US"); $us_locale = localeconv(); // Set and retrieve French locale setlocale(LC_ALL, "fr_FR"); $fr_locale = localeconv(); // Display differences echo "US Decimal Point: " . $us_locale['decimal_point'].PHP_EOL; echo "French Decimal Point: " . $fr_locale['decimal_point'].PHP_EOL; echo "US Currency Symbol: " . $us_locale['currency_symbol'].PHP_EOL; echo "French Currency Symbol: " . $fr_locale['currency_symbol'].PHP_EOL; ?>
Output
This will create the below output −
US Decimal Point: . French Decimal Point: , US Currency Symbol: $ French Currency Symbol: Eu