Showing posts with label PHP setlocale function. Show all posts
Showing posts with label PHP setlocale function. Show all posts

Friday, April 24, 2009

Some PHP Exercises

What is the use of the setlocale() function?

Write a program to set your locale information to the UK and then revert back to your default locale information.

The setlocale() function

This function could be used to set locale information such as time, language, monetary and geographical information.

syntax: setlocale(constant, location);

constant – specifies what locale information should be set.
This parameter can contains the following values:
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 – This parameter specifies which location the locale information should be set for.

The location parameter can hold a string or an array. In case of a string, the country/region code needs to be specifued.

If you are passing an array, the setlocale() function will scan through each of the array elements until it finds a valid region or country code and sets locale information for that region or country.

In order to setyour default locale information , you could use

setlocale(LC_ALL,NULL);

Example input:

echo setlocale(LC_ALL,"En-Us");
In this example, we are setting the locale information to that of the US.

Example output:

English_United States.1252