PHP Saturday, April 07, 2001  
downloads | documentation | faq | support | reporting bugs | links 

search for in the  

PHP HandbuchPHP Handbuch


Last updated: Wed, 04 Apr 2001
view this page in English | Brazilian Portuguese | Czech | Dutch | French | German | Hungarian | Italian | Japanese | Korean | Spanish | Plain HTML


(PHP 3, PHP 4 )

setlocale -- Setzt lokale Informationen


string setlocale (string category, string locale)

Der String category enthält die Kategorie der zu ändernden Lokalitäts-Informationen:

  • LC_ALL - alle folgenden Werte

  • LC_COLLATE - für String-Vergleiche - z.Zt. noch nicht in PHP implementiert

  • LC_CTYPE - betrifft Klassifizierungen und Umwandlung, z.B. bei strtoupper()

  • LC_MONETARY - betrifft localeconv() - z.Zt. noch nicht in PHP implementiert

  • LC_NUMERIC - für das Dezimal-Trennzeichen

  • LC_TIME - betrifft Zeit und Datums-Formatierungen durch strftime()

Ist locale als Leer-String definiert, also "", werden die Werte an Hand der entsprechenden Umgebungs-Variablen gleichen Namens oder von "LANG" bestimmt.

Ist locale Null oder "0", werden keine Einstellungen verändert sondern als Ergebnis zurück gegeben.

Setlocale() gibt die neue Einstellung oder false (wenn die locale-Funktionalität auf der System-Plattform nicht unterstützt wird oder der Kategorie-Wert ungültig ist) zurück. Ein ungültiger Kategorie-Name erzeugt auch noch eine Warnmeldung.

User Contributed Notes: setlocale
Michal Fita <>
11-Jan-1999 11:41
It is written nowhere, that setlocale() can be used for simple mathematical operations like adding, substracting, dividing or multiplying. The code below gives correct results:

setlocale("LC_ALL", "pl");
$net = "1234,56";
$gross = "1,22" * $net;
printf("gross: %s, net: %s", $gross, $net");
/* Polish VAT tax is 22% */

Result of this code is:
gross: 1234,56, net: 1506,1632
So, every one can use his own decimal point for mathematical operations without any error or warning (PHP3.0.3).

Lucas Thompson <>
31-Jan-2000 02:57
The Open Group has an excellent document available on the setlocale() library function, most of which applies to the PHP function of the same name.

WARNING: This document might be a little too complex for people who came from HTML to PHP.

If you migrated from the world of C programming you'll be a locale master after reading this document.

Morgan Christiansson &lt;;
29-Mar-2000 12:56
check /usr/share/locale/ if you want more info about the locale available with your *NIX box

there is also a file called /usr/share/locale/locale.alias with a list of aliases
such as swedish for sv_SE

so on all boxes i have accounts on (rh 6.0 and slack 3.4) you can just use setlocale("LC_ALL","swedish"); or other prefered language in plain english.

However, the weekdays were in all lowercase :(

Note: export LC_ALL=swedish made a lot of programs swedish for me, it's also possible to make them russian or japanese :)
15-Jul-2000 07:40
I used setlocale and then strftime like this:

echo strftime("%A",$timestamp);

Works prefectly under Windows.
23-Nov-2000 03:13
On windows:
Control Panel->International Settings
You can set your locale and customize it
And locale-related PHP functions work perfectly
14-Dec-2000 07:19
Language information is defined by this RFC:
RFC1766 - Tags for the Identification of Languages -

And the 2 letter codes come from:
ISO639: "Code for the representation of names of languages" -
ISO3166-1: "English country names and code elements" -

Also note that the language name can be used in full (ex: setlocale('LC_TIME','swedish'); ) . This full name comes from the latest mentioned file.
14-Dec-2000 07:20
BTW, not all locales are always supported on every server. Ask you ISP/network admin to see if they are.

Last updated: Wed, 04 Apr 2001
add note | about notes

show source | credits | stats | mirror sites:  

Copyright © 1998-2001 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Thu Apr 5 15:50:02 2001 EDT