mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-25 21:38:56 +00:00

- array functions - datetime functions - mbstring functions - strings functions - var functions - xml functions - json functions
248 lines
8 KiB
XML
248 lines
8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<refentry xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://docbook.org/ns/docbook" xml:id="function.setlocale">
|
|
<refnamediv>
|
|
<refname>setlocale</refname>
|
|
<refpurpose>Set locale information</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>string</type><type>false</type></type><methodname>setlocale</methodname>
|
|
<methodparam><type>int</type><parameter>category</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>locales</parameter></methodparam>
|
|
<methodparam rep="repeat"><type>string</type><parameter>rest</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>Alternative signature (not supported with named arguments):</simpara>
|
|
<methodsynopsis>
|
|
<type class="union"><type>string</type><type>false</type></type><methodname>setlocale</methodname>
|
|
<methodparam><type>int</type><parameter>category</parameter></methodparam>
|
|
<methodparam><type>array</type><parameter>locale_array</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Sets locale information.
|
|
</para>
|
|
<warning>
|
|
<para>
|
|
The locale information is maintained per process, not per thread. If you
|
|
are running PHP on a multithreaded server API
|
|
, you may experience sudden changes in locale settings while a
|
|
script is running, though the script itself never called
|
|
<function>setlocale</function>. This happens due to other scripts
|
|
running in different threads of the same process at the same time,
|
|
changing the process-wide locale using <function>setlocale</function>.
|
|
On Windows, locale information is maintained per thread as of PHP 7.0.5.
|
|
</para>
|
|
</warning>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>category</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<parameter>category</parameter> is a named constant specifying the
|
|
category of the functions affected by the locale setting:
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>LC_ALL</constant> for all of the below
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>LC_COLLATE</constant> for string comparison, see
|
|
<function>strcoll</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>LC_CTYPE</constant> for character classification and conversion, for
|
|
example <function>strtoupper</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>LC_MONETARY</constant> for <function>localeconv</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>LC_NUMERIC</constant> for decimal separator (See also
|
|
<function>localeconv</function>)
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>LC_TIME</constant> for date and time formatting with
|
|
<function>strftime</function>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<constant>LC_MESSAGES</constant> for system responses (available if PHP was compiled with
|
|
<literal>libintl</literal>)
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>locales</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
If <parameter>locales</parameter> is the empty string
|
|
<literal>""</literal>, the locale names will be set from the
|
|
values of environment variables with the same names as the above
|
|
categories, or from "LANG".
|
|
</para>
|
|
<para>
|
|
If <parameter>locales</parameter> is <literal>"0"</literal>,
|
|
the locale setting is not affected, only the current setting is returned.
|
|
</para>
|
|
<para>
|
|
If <parameter>locales</parameter> is followed by additional
|
|
parameters then each parameter is tried to be set as
|
|
new locale until success. This is useful if a locale is known under
|
|
different names on different systems or for providing a fallback
|
|
for a possibly not available locale.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>rest</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Optional string parameters to try as locale settings until
|
|
success.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>locale_array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Each array element is tried to be set as
|
|
new locale until success. This is useful if a locale is known under
|
|
different names on different systems or for providing a fallback
|
|
for a possibly not available locale.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
<note>
|
|
<para>
|
|
On Windows, setlocale(LC_ALL, '') sets the locale names from the
|
|
system's regional/language settings (accessible via Control Panel).
|
|
</para>
|
|
</note>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Returns the new current locale, or &false; if the locale functionality is
|
|
not implemented on your platform, the specified locale does not exist or
|
|
the category name is invalid.
|
|
</para>
|
|
<para>
|
|
An invalid category name also causes a warning message. Category/locale
|
|
names can be found in <link xlink:href="&url.rfc;1766">RFC 1766</link>
|
|
and <link xlink:href="&url.iso-639;">ISO 639</link>.
|
|
Different systems have different naming schemes for locales.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
The return value of <function>setlocale</function> depends
|
|
on the system that PHP is running. It returns exactly
|
|
what the system <literal>setlocale</literal> function returns.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>setlocale</function> Examples</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/* Set locale to Dutch */
|
|
setlocale(LC_ALL, 'nl_NL');
|
|
|
|
/* Output: vrijdag 22 december 1978 */
|
|
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));
|
|
|
|
/* try different possible locale names for german */
|
|
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
|
echo "Preferred locale for german on this system is '$loc_de'";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>setlocale</function> Examples for Windows</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/* Set locale to Dutch */
|
|
setlocale(LC_ALL, 'nld_nld');
|
|
|
|
/* Output: vrijdag 22 december 1978 */
|
|
echo strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));
|
|
|
|
/* try different possible locale names for german */
|
|
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
|
|
echo "Preferred locale for german on this system is '$loc_de'";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<tip>
|
|
<para>
|
|
Windows users will find useful information about
|
|
<parameter>locales</parameter> strings at Microsoft's
|
|
<acronym>MSDN</acronym> website. Supported language strings can be found
|
|
in the
|
|
<link xlink:href="&url.setlocale.lang.win32;">language strings documentation</link>
|
|
and supported country/region strings in the
|
|
<link xlink:href="&url.setlocale.country.win32;">country/region strings documentation</link>.
|
|
</para>
|
|
</tip>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|