<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >setlocale</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="String 字符串处理函数" HREF="ref.strings.html"><LINK REL="PREVIOUS" TITLE="rtrim" HREF="function.rtrim.html"><LINK REL="NEXT" TITLE="sha1_file" HREF="function.sha1-file.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.rtrim.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.sha1-file.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.setlocale" ></A >setlocale</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN226595" ></A ><P > (PHP 3, PHP 4, PHP 5)</P >setlocale -- Set locale information</DIV ><DIV CLASS="refsect1" ><A NAME="AEN226598" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >setlocale</B > ( int category, string locale [, string ...] )<BR ></BR >string <B CLASS="methodname" >setlocale</B > ( int category, array locale )<BR ></BR ><P > <CODE CLASS="parameter" >category</CODE > is a named constant (or string) specifying the category of the functions affected by the locale setting: <P ></P ><UL ><LI ><P > LC_ALL for all of the below </P ></LI ><LI ><P > LC_COLLATE for string comparison, see <A HREF="function.strcoll.html" ><B CLASS="function" >strcoll()</B ></A > </P ></LI ><LI ><P > LC_CTYPE for character classification and conversion, for example <A HREF="function.strtoupper.html" ><B CLASS="function" >strtoupper()</B ></A > </P ></LI ><LI ><P > LC_MONETARY for <A HREF="function.localeconv.html" ><B CLASS="function" >localeconv()</B ></A > </P ></LI ><LI ><P > LC_NUMERIC for decimal separator (See also <A HREF="function.localeconv.html" ><B CLASS="function" >localeconv()</B ></A >) </P ></LI ><LI ><P > LC_TIME for date and time formatting with <A HREF="function.strftime.html" ><B CLASS="function" >strftime()</B ></A > </P ></LI ><LI ><P > LC_MESSAGES for system responses (available if PHP was compiled with <TT CLASS="literal" >libintl</TT >) </P ></LI ></UL > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > As of PHP 4.2.0, passing <CODE CLASS="parameter" >category</CODE > as a string is deprecated, use the above constants instead. Passing them as a string (within quotes) will result in a warning message. </P ></BLOCKQUOTE ></DIV ><P > If <CODE CLASS="parameter" >locale</CODE > is <TT CLASS="constant" ><B >NULL</B ></TT > or the empty string <TT CLASS="literal" >""</TT >, the locale names will be set from the values of environment variables with the same names as the above categories, or from "LANG". </P ><P > If <CODE CLASS="parameter" >locale</CODE > is <TT CLASS="literal" >"0"</TT >, the locale setting is not affected, only the current setting is returned. </P ><P > If <CODE CLASS="parameter" >locale</CODE > is an array or followed by additional parameters then each array element or 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. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > Passing multiple locales is not available before PHP 4.3.0 </P ></BLOCKQUOTE ></DIV ><P > Setlocale returns the new current locale, or <TT CLASS="constant" ><B >FALSE</B ></TT > if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid. An invalid category name also causes a warning message. Category/locale names can be found in <A HREF="http://www.faqs.org/rfcs/rfc1766" TARGET="_top" >RFC 1766</A > and <A HREF="http://www.w3.org/WAI/ER/IG/ert/iso639.htm" TARGET="_top" >ISO 639</A >. Different systems have different naming schemes for locales. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > The return value of <B CLASS="function" >setlocale()</B > depends on the system that PHP is running. It returns exactly what the system setlocale function returns. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >警告</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server api like IIS or Apache on Windows you may experience sudden changes of locale settings while a script is running although the script itself never called <B CLASS="function" >setlocale()</B > itself. This happens due to other scripts running in different threads of the same process at the same time changing the processwide locale using <B CLASS="function" >setlocale()</B >. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="tip" ><BLOCKQUOTE CLASS="tip" ><P ><B >提示: </B > Windows users will find useful information about <CODE CLASS="parameter" >locale</CODE > strings at Microsoft's <ACRONYM CLASS="acronym" >MSDN</ACRONYM > website. Supported language strings can be found at <A HREF="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_language_strings.asp" TARGET="_top" >http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_language_strings.asp</A > and supported country/region strings at <A HREF="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_country_strings.asp" TARGET="_top" >http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_country_strings.asp</A >. Windows systems support the three letter codes for country/region specified by <TT CLASS="literal" >ISO 3166-Alpha-3</TT >, which can be found at this <A HREF="http://www.unicode.org/onlinedat/countries.html" TARGET="_top" >Unicode website</A >. </P ></BLOCKQUOTE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN226678" ></A ><P ><B >例 1. <B CLASS="function" >setlocale()</B > Examples</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Set locale to Dutch */<br /></font><font color="#0000BB">setlocale</font><font color="#007700">(</font><font color="#0000BB">LC_ALL</font><font color="#007700">, </font><font color="#DD0000">'nl_NL'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Output: vrijdag 22 december 1978 */<br /></font><font color="#007700">echo </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%A %e %B %Y"</font><font color="#007700">, </font><font color="#0000BB">mktime</font><font color="#007700">(</font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">12</font><font color="#007700">, </font><font color="#0000BB">22</font><font color="#007700">, </font><font color="#0000BB">1978</font><font color="#007700">));<br /><br /></font><font color="#FF8000">/* try different possible locale names for german as of PHP 4.3.0 */<br /></font><font color="#0000BB">$loc_de </font><font color="#007700">= </font><font color="#0000BB">setlocale</font><font color="#007700">(</font><font color="#0000BB">LC_ALL</font><font color="#007700">, </font><font color="#DD0000">'de_DE@euro'</font><font color="#007700">, </font><font color="#DD0000">'de_DE'</font><font color="#007700">, </font><font color="#DD0000">'de'</font><font color="#007700">, </font><font color="#DD0000">'ge'</font><font color="#007700">);<br />echo </font><font color="#DD0000">"Preferred locale for german on this system is '$loc_de'"</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN226683" ></A ><P ><B >例 2. <B CLASS="function" >setlocale()</B > Examples for Windows</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Set locale to Dutch */<br /></font><font color="#0000BB">setlocale</font><font color="#007700">(</font><font color="#0000BB">LC_ALL</font><font color="#007700">, </font><font color="#DD0000">'nld_nld'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Output: vrijdag 22 december 1978 */<br /></font><font color="#007700">echo </font><font color="#0000BB">strftime</font><font color="#007700">(</font><font color="#DD0000">"%A %d %B %Y"</font><font color="#007700">, </font><font color="#0000BB">mktime</font><font color="#007700">(</font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">, </font><font color="#0000BB">12</font><font color="#007700">, </font><font color="#0000BB">22</font><font color="#007700">, </font><font color="#0000BB">1978</font><font color="#007700">));<br /><br /></font><font color="#FF8000">/* try different possible locale names for german as of PHP 4.3.0 */<br /></font><font color="#0000BB">$loc_de </font><font color="#007700">= </font><font color="#0000BB">setlocale</font><font color="#007700">(</font><font color="#0000BB">LC_ALL</font><font color="#007700">, </font><font color="#DD0000">'de_DE@euro'</font><font color="#007700">, </font><font color="#DD0000">'de_DE'</font><font color="#007700">, </font><font color="#DD0000">'deu_deu'</font><font color="#007700">);<br />echo </font><font color="#DD0000">"Preferred locale for german on this system is '$loc_de'"</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.rtrim.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.sha1-file.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >rtrim</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.strings.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >sha1_file</TD ></TR ></TABLE ></DIV ></BODY ></HTML >