php.ini 中的 PHP 语言环境配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5075145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Php locale configuration in php.ini
提问by danidacar
Can a default locale value be places in php.ini or .htaccess ?
默认语言环境值可以放在 php.ini 或 .htaccess 中吗?
The equivalent of the php function
相当于php函数
setlocale(LC_MONETARY, 'it_IT');
for example
例如
回答by David Kurid?a
It can, take a look at intl.default_locale
.
可以的,看看intl.default_locale
。
回答by mario
There's nothing in the php.ini to help you. But as alternative you could try setting environment variables from .htaccess
php.ini 中没有任何内容可以帮助您。但作为替代方案,您可以尝试从 .htaccess 设置环境变量
SetEnv LC_ALL it_IT.UTF-8
But these settings only take effect for CGI and FastCGI versions of PHP at best, not for the usual mod_php installation.
但是这些设置充其量只对 CGI 和 FastCGI 版本的 PHP 生效,而不对通常的 mod_php 安装生效。
回答by JulienCC
Sadly there is no way at this time to set this configuration PHP wide.
I've been looking at the code and the ENV method doesn't work since LC_*
variables are not treated like the other ones.
遗憾的是,目前无法在 PHP 范围内设置此配置。我一直在查看代码并且 ENV 方法不起作用,因为LC_*
变量不像其他变量那样被对待。
You can patch PHP to use your locale instead of the default 'C'
one or make a module if you really need to.
'C'
如果确实需要,您可以修补 PHP 以使用您的语言环境而不是默认语言环境或创建一个模块。
But the actual way to go is to do it at the script level.
但实际的方法是在脚本级别进行。
EDIT: using auto_prepend_file in php.ini lets you run add some code before any script executed, so it looks like a nice place to use setlocale.
编辑:在 php.ini 中使用 auto_prepend_file 可以让您在执行任何脚本之前运行添加一些代码,因此它看起来是使用 setlocale 的好地方。