How to use setlocale in PHP

In this article I will explain how the setlocale() function can be used in PHP.
  • 1871

setlocale() function in PHP

  • The setlocale() function is used to set locale information.
  • In setlocale() function, locale information is time, monetary, language and other information specific for a geographical area.
  • The setlocale() function returns the current locale settings on success.
  • The setlocale() function returns False on failure.
  • The return value of setlocale() depends on the system

Syntax

setlocale(constant,location)

Parameter

  • constant constant is required parameter. it should be set locale information. some available constants:
    • LC_ALL - All of the below
    • LC_COLLATE -  Sort order
    • LC_CTYPE - Character classification and conversion (e.g. all characters should be lower or upper-case)
    • LC_MESSAGES - System message formatting
    • LC_MONETARY - Monetary/currency formatting
    • LC_NUMERIC - Numeric formatting
    • LC_TIME - Date and time formatting
  • location location is required parameter. it is set the locale information. it can be a string or an array. setlocale() will try each array element until it finds a valid language or region code, if the location is an array . it is very useful for a region is known under different names on different systems.

Example

The following example show to how the setlocale() function can be used in PHP.

<html>

<body>

<h3 style="color: blueviolet;">setlocale() function example in PHP</h3>

   <?php

    echo setlocale(LC_ALL,"En-Us");

    echo "<br />";

    echo setlocale(LC_ALL,NULL);

    ?>

</body>

</html>

 

Output

setlocale-php.gif
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.