德国Umlauts采用strftime日期格式-正确的utf-8编码吗? [英] German Umlauts in strftime date-formatting - correct utf-8 encoding?
问题描述
我正在使用PHP 14. März 2012
(这是2012年3月14日)创建这样的德语日期格式.
I'm creating a german date format like this with PHP 14. März 2012
(which is March 14th 2012).
我正在使用$date[0]
,它包含一个unix时间戳,我将其像这样转换为可读的德语日期.
I'm working with $date[0]
that contains a unix timestamp and I convert it like this to a readable german date.
$date_day_month = strftime('%d. %B', $date[0]);
$date_year = strftime('%Y', $date[0]);
echo $date_day_month . $date_year;
但是我却以某种方式为Umlaut ä
提出了一个问号
However I somehow get a question mark for the Umlaut ä
like this
14. M�rz 2012
为什么会这样,我该如何解决?预先感谢.
Why is that and how can I fix this? Thanks in advance.
推荐答案
您可以尝试将网页utf-8放入head
标记中:
You could try to make your webpage utf-8, put this in your head
tag:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
strftime
取决于语言环境的正确设置,因此请检查您的setlocale()
并确保php运行的计算机上存在语言环境.
strftime
is depending on the right setting of the locale, so check your setlocale()
and make sure that locale exists on the machine that php has running.
更新
我在服务器上运行了这段代码:
I ran this code on my server:
setlocale(LC_ALL, 'de_DE');
$date[0] = mktime( 1, 0, 0, 3, 2, 2012 );
$date_day_month = strftime('%d. %B', $date[0]);
$date_year = strftime('%Y', $date[0]);
echo $date_day_month . $date_year;
然后输出:
02. März2012
这篇关于德国Umlauts采用strftime日期格式-正确的utf-8编码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!