Source of: /manual/en/function.locale-set-default.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.i18n.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.locale-set-default.php',
1 => 'locale_set_default',
),
'up' =>
array (
0 => 'ref.i18n.php',
1 => 'i18n Functions',
),
'prev' =>
array (
0 => 'function.locale-get-default.php',
1 => 'locale_get_default',
),
'next' =>
array (
0 => 'book.iconv.php',
1 => 'iconv',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.locale-set-default" class="refentry">
<div class="refnamediv">
<h1 class="refname">locale_set_default</h1>
<p class="verinfo">(PHP 5 >= 5.3.0, PECL intl >= 1.0.0)</p><p class="refpurpose"><span class="refname">locale_set_default</span> — <span class="dc-title">Set the default Locale</span></p>
</div>
<a name="function.locale-set-default.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><a href="locale.setdefault.php" class="function">locale_set_default</a></span>
( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$name</tt></span>
)</div>
<p class="para rdfs-comment">
Sets the default Locale for PHP programs. Please note that this has nothing
to do with <a href="function.setlocale.php" class="function">setlocale()</a> nor with the system locale.
</p>
</div>
<a name="function.locale-set-default.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">name</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The new Locale name. A comprehensive list of the supported locales is
available at <a href="http://demo.icu-project.org/icu-bin/locexp" class="link external">» http://demo.icu-project.org/icu-bin/locexp</a>.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.locale-set-default.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
</p>
</div>
<a name="function.locale-set-default.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 A <a href="locale.setdefault.php" class="function">locale_set_default()</a> example</b></p>
<div class="example-contents para"><p>
This example demonstrates a possible usage of
<a href="locale.setdefault.php" class="function">locale_set_default()</a> to localize the
<a href="function.sort.php" class="function">sort()</a> functions.
</p></div>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// the list of the strings to sort<br /></span><span style="color: #0000BB">$array </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'caramelo'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'cacto'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'caçada'<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// set our locale (Portuguese, in this case)<br /></span><span style="color: #0000BB">locale_set_default</span><span style="color: #007700">(</span><span style="color: #DD0000">'pt_PT'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// sort using the locale we previously set<br /></span><span style="color: #0000BB">sort</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">, </span><span style="color: #0000BB">SORT_LOCALE_STRING</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents para"><p>The above example will output:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Array
(
[0] => caçada
[1] => cacto
[2] => caramelo
)
</pre></div>
</div>
<div class="example-contents para"><p>
If we didn't use the locale, PHP would sort the string using the ASCII
characters value, thus returning (wrongly):
</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Array
(
[0] => cacto
[1] => caramelo
[2] => caçada
)
</pre></div>
</div>
</div><p>
</p>
</div>
<a name="function.locale-set-default.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="locale.getdefault.php" class="function" rel="rdfs-seeAlso">locale_get_default()</a> - Gets the default locale value from the INTL global 'default_locale'</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>