downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

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 &gt;= 5.3.0, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">locale_set_default</span> &mdash; <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">&raquo; 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">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;the&nbsp;list&nbsp;of&nbsp;the&nbsp;strings&nbsp;to&nbsp;sort<br /></span><span style="color: #0000BB">$array&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'caramelo'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cacto'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'caçada'<br /></span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;set&nbsp;our&nbsp;locale&nbsp;(Portuguese,&nbsp;in&nbsp;this&nbsp;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">//&nbsp;sort&nbsp;using&nbsp;the&nbsp;locale&nbsp;we&nbsp;previously&nbsp;set<br /></span><span style="color: #0000BB">sort</span><span style="color: #007700">(</span><span style="color: #0000BB">$array</span><span style="color: #007700">,&nbsp;</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">?&gt;</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] =&gt; caçada
    [1] =&gt; cacto
    [2] =&gt; caramelo
)
</pre></div>
    </div>
    <div class="example-contents para"><p>
     If we didn&#039;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] =&gt; cacto
    [1] =&gt; caramelo
    [2] =&gt; 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(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites