mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 13:57:03 +08:00
253 lines
14 KiB
HTML
253 lines
14 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
<title>设置地区信息</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.setlocale" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">setlocale</h1>
|
||
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">setlocale</span> — <span class="dc-title">设置地区信息</span></p>
|
||
|
||
</div>
|
||
|
||
<div class="refsect1 description" id="refsect1-function.setlocale-description">
|
||
<h3 class="title">说明</h3>
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>setlocale</strong></span>
|
||
( <span class="methodparam"><span class="type">int</span> <code class="parameter">$category</code></span>
|
||
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>
|
||
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$...</code></span>
|
||
] ) : <span class="type">string</span></div>
|
||
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>setlocale</strong></span>
|
||
( <span class="methodparam"><span class="type">int</span> <code class="parameter">$category</code></span>
|
||
, <span class="methodparam"><span class="type">array</span> <code class="parameter">$locale</code></span>
|
||
) : <span class="type">string</span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
设置地区信息。
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 parameters" id="refsect1-function.setlocale-parameters">
|
||
<h3 class="title">参数</h3>
|
||
<p class="para">
|
||
<dl>
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">category</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
<code class="parameter">category</code> 命名常量指定的受区域设置的功能类别:
|
||
<ul class="itemizedlist">
|
||
<li class="listitem">
|
||
<span class="simpara">
|
||
<strong><code>LC_ALL</code></strong> 所有的设置
|
||
</span>
|
||
</li>
|
||
<li class="listitem">
|
||
<span class="simpara">
|
||
<strong><code>LC_COLLATE</code></strong> 字符串比较, 详见
|
||
<span class="function"><a href="strcoll.html" class="function">strcoll()</a></span>
|
||
</span>
|
||
</li>
|
||
<li class="listitem">
|
||
<span class="simpara">
|
||
<strong><code>LC_CTYPE</code></strong> 字符串的分类与转换, 参见例子
|
||
<span class="function"><a href="strtoupper.html" class="function">strtoupper()</a></span>
|
||
</span>
|
||
</li>
|
||
<li class="listitem">
|
||
<span class="simpara">
|
||
<strong><code>LC_MONETARY</code></strong> 等同 <span class="function"><a href="localeconv.html" class="function">localeconv()</a></span>
|
||
</span>
|
||
</li>
|
||
<li class="listitem">
|
||
<span class="simpara">
|
||
<strong><code>LC_NUMERIC</code></strong> 对于小数点的分隔 (另请参见
|
||
<span class="function"><a href="localeconv.html" class="function">localeconv()</a></span>)
|
||
</span>
|
||
</li>
|
||
<li class="listitem">
|
||
<span class="simpara">
|
||
<strong><code>LC_TIME</code></strong> 时间与格式
|
||
<span class="function"><a href="strftime.html" class="function">strftime()</a></span>
|
||
</span>
|
||
</li>
|
||
<li class="listitem">
|
||
<span class="simpara">
|
||
<strong><code>LC_MESSAGES</code></strong> 系统响应 (如果PHP使用<em>libintl</em>编译)
|
||
</span>
|
||
</li>
|
||
</ul>
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">locale</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
If <code class="parameter">locale</code> is <strong><code>NULL</code></strong> or the empty string
|
||
<em>""</em>, 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 class="para">
|
||
If <code class="parameter">locale</code> is <em>"0"</em>,
|
||
the locale setting is not affected, only the current setting is returned.
|
||
</p>
|
||
<p class="para">
|
||
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>
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">...</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
(可使用字符串或数组参数进行尝试直到设置成功。)
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
</dl>
|
||
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
在Windows中,setlocale(LC_ALL, '')要从系统中的区域/语言设置(通过控制面板访问) 。
|
||
</p>
|
||
</p></blockquote>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.setlocale-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
Returns the new current locale, or <strong><code>FALSE</code></strong> if the locale functionality is
|
||
not implemented on your platform, the specified locale does not exist or
|
||
the category name is invalid.
|
||
</p>
|
||
<p class="para">
|
||
An invalid category name also causes a warning message. Category/locale
|
||
names can be found in <a href="http://www.faqs.org/rfcs/rfc1766" class="link external">» RFC 1766</a>
|
||
and <a href="http://www.w3.org/WAI/ER/IG/ert/iso639.htm" class="link external">» ISO 639</a>.
|
||
Different systems have different naming schemes for locales.
|
||
</p>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
The return value of <span class="function"><strong>setlocale()</strong></span> depends
|
||
on the system that PHP is running. It returns exactly
|
||
what the system <em>setlocale</em> function returns.
|
||
</p>
|
||
</p></blockquote>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 changelog" id="refsect1-function.setlocale-changelog">
|
||
<h3 class="title">更新日志</h3>
|
||
<p class="para">
|
||
<table class="doctable informaltable">
|
||
|
||
<thead>
|
||
<tr>
|
||
<th>版本</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
|
||
</thead>
|
||
|
||
<tbody class="tbody">
|
||
<tr>
|
||
<td>5.3.0</td>
|
||
<td>
|
||
This function now throws an <strong><code>E_DEPRECATED</code></strong> notice if a string is passed
|
||
to the <code class="parameter">category</code> parameter instead of one of the
|
||
<em>LC_*</em> constants.
|
||
</td>
|
||
</tr>
|
||
|
||
</tbody>
|
||
|
||
</table>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 examples" id="refsect1-function.setlocale-examples">
|
||
<h3 class="title">范例</h3>
|
||
<p class="para">
|
||
<div class="example" id="metaphone.example.basic">
|
||
<p><strong>Example #1 <span class="function"><strong>setlocale()</strong></span> Examples</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Set locale to Dutch */<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">, </span><span style="color: #DD0000">'nl_NL'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Output: vrijdag 22 december 1978 */<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%A %e %B %Y"</span><span style="color: #007700">, </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">12</span><span style="color: #007700">, </span><span style="color: #0000BB">22</span><span style="color: #007700">, </span><span style="color: #0000BB">1978</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/* try different possible locale names for german as of PHP 4.3.0 */<br /></span><span style="color: #0000BB">$loc_de </span><span style="color: #007700">= </span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">, </span><span style="color: #DD0000">'de_DE@euro'</span><span style="color: #007700">, </span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">, </span><span style="color: #DD0000">'de'</span><span style="color: #007700">, </span><span style="color: #DD0000">'ge'</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Preferred locale for german on this system is '</span><span style="color: #0000BB">$loc_de</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
</div>
|
||
</p>
|
||
<p class="para">
|
||
<div class="example" id="metaphone.example.phonemes">
|
||
<p><strong>Example #2 <span class="function"><strong>setlocale()</strong></span> Examples for Windows</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Set locale to Dutch */<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">, </span><span style="color: #DD0000">'nld_nld'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Output: vrijdag 22 december 1978 */<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">strftime</span><span style="color: #007700">(</span><span style="color: #DD0000">"%A %d %B %Y"</span><span style="color: #007700">, </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">12</span><span style="color: #007700">, </span><span style="color: #0000BB">22</span><span style="color: #007700">, </span><span style="color: #0000BB">1978</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/* try different possible locale names for german as of PHP 4.3.0 */<br /></span><span style="color: #0000BB">$loc_de </span><span style="color: #007700">= </span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_ALL</span><span style="color: #007700">, </span><span style="color: #DD0000">'de_DE@euro'</span><span style="color: #007700">, </span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">, </span><span style="color: #DD0000">'deu_deu'</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"Preferred locale for german on this system is '</span><span style="color: #0000BB">$loc_de</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
</div>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 notes" id="refsect1-function.setlocale-notes">
|
||
<h3 class="title">注释</h3>
|
||
<div class="warning"><strong class="warning">Warning</strong>
|
||
<p class="para">
|
||
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 in locale settings while a
|
||
script is running, though the script itself never called
|
||
<span class="function"><strong>setlocale()</strong></span>. This happens due to other scripts
|
||
running in different threads of the same process at the same time,
|
||
changing the process-wide locale using <span class="function"><strong>setlocale()</strong></span>.
|
||
</p>
|
||
</div>
|
||
<div class="tip"><strong class="tip">Tip</strong>
|
||
<p class="para">
|
||
Windows users will find useful information about
|
||
<code class="parameter">locale</code> strings at Microsoft's
|
||
<acronym title="Microsoft Developer Network">MSDN</acronym> website. Supported language strings can be found
|
||
in the
|
||
<a href="http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.90%29.aspx" class="link external">» language strings documentation</a>
|
||
and supported country/region strings in the
|
||
<a href="http://msdn.microsoft.com/en-us/library/cdax410z%28v=vs.90%29.aspx" class="link external">» country/region strings documentation</a>.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div></div></div></body></html> |