Recipe 19.3. Setting the Default Locale

19.3.1. Problem

You want to set a locale that all your PHP programs can use.

19.3.2. Solution

At the beginning of a file loaded by the auto_prepend_file configuration directive, call setlocale( ) to set your desired locale, as in Example 19-2.

Setting a default locale

<?php setlocale(LC_ALL,'es_US'); ?>

To use whatever default is set by the system environment variables, pass null as the locale to setlocale( ), as in Example 19-3.

Setting a default locale based on system environment

<?php setlocale(LC_ALL,null); ?>

19.3.3. Discussion

Even if you set up appropriate environment variables before you start your web server or PHP binary, PHP doesn't change its locale until you call setlocale( ). After setting environment variable LC_ALL to es_US, for example, PHP still runs in the default C locale.

19.3.4. See Also

Recipe 19.2 shows how to use a particular locale; documentation on setlocale( ) at and auto_prepend_file at

PHP Cookbook, 2nd Edition
PHP Cookbook: Solutions and Examples for PHP Programmers
ISBN: 0596101015
EAN: 2147483647
Year: 2006
Pages: 445

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: