16.3. Setting the Default Locale

Problem

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

Solution

At the beginning of a file loaded by the auto_prepend_file configuration directive, call setlocale( ) to set your desired locale:

setlocale(LC_ALL,'es_US');

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.

See Also

Section 16.3 shows how to use a particular locale; documentation on setlocale( ) at http://www.php.net/setlocale and auto_prepend_file at http://www.php.net/manual/en/configuration.directives.php#ini.auto-prepend-file.

Get PHP Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.