PHP setlocale 没有效果 [英] PHP setlocale has no effect
问题描述
setlocale()
函数没有设置所需的语言(德语).
目标是输出月份名称.
这是我到目前为止的试验代码:
输出:
<块引用>六月
代替
<块引用>六月
有什么建议吗?
- 我没有 ssh 或其他 shell 访问权限.
- 脚本在 Linux 服务器上运行.
PHP 5.6 版
如果您没有对服务器的 shell 访问权限,此解决方案可能会有所帮助.
如果您有 shell 访问权限,那么 Benjamin Seiller 的答案 是最好的!>
由于我没有任何其他可能性(shell),我通过使用 IntlDateFormatter 类.
format($lastMonth);回声 $showLastMonth;
The setlocale()
function doesn't set the desired language (German).
The goal is to output month names.
This is my test code with trials so far:
<?php
date_default_timezone_set('Europe/Berlin');
setlocale(LC_ALL, 'de_DE.utf8');
// Or
setlocale(LC_ALL, 'de_DE@euro');
// Or
setlocale(LC_ALL, 'de_DE');
// Or
setlocale(LC_ALL, 'de');
// Or
setlocale(LC_ALL, 'ge');
echo strftime('%B');
Output:
June
instead of
Juni
Any suggestions?
- I don't have ssh or other shell access.
- The script is running on a linux server.
PHP version 5.6
This solution might help if you don't have shell access to the server.
If you have shell access, then Benjamin Seiller's answer is the best!
As I don't have any other possibilities (shell), I've found a solution with only PHP by using the IntlDateFormatter class.
<?php
// Example vars
$month = '6';
$year = '2014';
$fmt = new IntlDateFormatter('de_DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Berlin',
IntlDateFormatter::GREGORIAN);
$lastMonth = mktime(0, 0, 0, $month -1, 1, $year);
$showLastMonth = $fmt->format($lastMonth);
echo $showLastMonth;
这篇关于PHP setlocale 没有效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!