PHP setlocale() Function

In this chapter you will learn:

  1. Definition for PHP setlocale() Function
  2. Syntax for PHP setlocale() Function
  3. Parameter for PHP setlocale() Function
  4. Locale information
  5. Return for PHP setlocale() Function
  6. Example - Set the locale to US English and then back to default again

Definition

The setlocale() function sets locale information for the current script.

Locale information is the information specific for a geographical area, for example the money letter, the language.

The locale information can be set to system default with setlocale(LC_ALL,NULL)

Syntax

PHP setlocale() Function has the following syntax.

setlocale(constant,location)

Parameter

ParameterIs RequiredDescription
constantRequired.What locale information should be set.
locationRequired.What country/region to set the locale information to. Can be a string or an array to pass multiple locations.

Locale information

Available value for constant:

  • 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

If the location is NULL or the empty string "", the location names will be set from the values of environment variables with the same names as the constants above, or from "LANG".

If the location is "0", the location setting is not affected, only the current setting is returned.

If the location is an array, setlocale() will try each array element until it finds a valid language or region code.

Return

PHP setlocale() Function returns the current locale settings, or FALSE on failure.

Example

Set the locale to US English and then back to default again:


<?php//from   jav a 2s. c  o m
echo setlocale(LC_ALL,"US");
echo "\n";
echo setlocale(LC_ALL,NULL);
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP sha1() Function
  2. Syntax for PHP sha1() Function
  3. Parameter for PHP sha1() Function
  4. Return for PHP sha1() Function
  5. Example - GEt the SHA1 hash value for strings
Home » PHP Tutorial » PHP String Functions
PHP addcslashes() Function
PHP addslashes() Function
PHP bin2hex() Function
PHP chop() Function
PHP chr() Function
PHP chunk_split() Function
PHP convert_cyr_string() Function
PHP convert_uudecode() Function
PHP convert_uuencode() Function
PHP count_chars() Function
PHP crc32() Function
PHP crypt() Function
PHP echo() Function
PHP get_html_translation_table() Function
PHP hebrev() Function
PHP hebrevc() Function
PHP hex2bin() Function
PHP html_entities() Function
PHP html_entity_decode() Function
PHP htmlspecialchars() Function
PHP htmlspecialchars_decode() Function
PHP join() Function
PHP lcfirst() Function
PHP levenshtein() Function
PHP localeconv() Function
PHP ltrim() Function
PHP md5() Function
PHP metaphone() Function
PHP money_format() Function
PHP nl2br() Function
PHP nl_langinfo() Function
PHP number_format() Function
PHP ord() Function
PHP parse_str() Function
PHP print() Function
PHP print_r() Function
PHP printf() Function
PHP quoted_printable_decode() Function
PHP quoted_printable_encode() Function
PHP quotemeta() Function
PHP rawurldecode() Function
PHP rawurlencode() Function
PHP rtrim() Function
PHP setlocale() Function
PHP sha1() Function
PHP similar_text() Function
PHP soundex() Function
PHP sprintf() Function
PHP sscanf() Function
PHP str_getcsv() Function
PHP str_ireplace() Function
PHP str_pad() Function
PHP str_repeat() Function
PHP str_replace() Function
PHP str_rot13() Function
PHP str_shuffle() Function
PHP str_split() Function
PHP str_word_count() Function
PHP strcasecmp() Function
PHP strchr() Function
PHP strcmp() Function
PHP strcoll() Function
PHP strcspn() Function
PHP strip_tags() Function
PHP stripcslashes() Function
PHP stripslashes() Function
PHP stristr() Function
PHP strlen() Function
PHP strnatcasecmp() Function
PHP strnatcmp() Function
PHP strncasecmp() Function
PHP strncmp() Function
PHP strpbrk() Function
PHP strpos() Function
PHP strrchr() Function
PHP strrev() Function
PHP strripos() Function
PHP strrpos() Function
PHP strspn() Function
PHP strstr() Function
PHP strtok() Function
PHP strtolower() Function
PHP strtoupper() Function
PHP strtr() Function
PHP substr() Function
PHP substr_compare() Function
PHP substr_count() Function
PHP substr_replace() Function
PHP trim() Function
PHP ucfirst() Function
PHP ucwords() Function
PHP utf8_decode() Function
PHP utf8_encode() Function
PHP vprintf() Function
PHP vsprintf() Function
PHP wordwrap() Function