【发布时间】:2013-02-06 19:26:48
【问题描述】:
我有这段代码,它通过 json_decode 检索我最新的推文、它们的日期等。
<?php setlocale(LC_ALL, 'it_IT'); ?>
<?php include("twitter_auth.php");
echo "<ul style='color:#6E6E6E'>";
foreach ($twitter_data as $tweet)
{
if (!empty($tweet)) {
$text = $tweet->text;
$text_in_tooltip = str_replace('"', '', $text); // replace " to avoid conflicts with title="" opening tags
$id = $tweet->id;
$time = strftime('%d %B', strtotime($tweet->created_at));
$username = $tweet->user->name;
}
echo '<li><span title="'; echo $text_in_tooltip; echo '">'; echo $text . "</span><br>
<a href=\"http://twitter.com/"; echo $username ; echo '/status/'; echo $id ; echo '"><small>'; echo $time; echo '</small></a> -
<a href="http://twitter.com/intent/tweet?in_reply_to='; echo $id; echo '"><small>rispondi</small></a> -
<a href="http://twitter.com/intent/retweet?tweet_id='; echo $id; echo '"><small>retweet</small></a> -
<a href="http://twitter.com/intent/favorite?tweet_id='; echo $id; echo '"><small>preferito</small></a></li>';
}
echo '</ul>';
?>
问题是 $time 会输出类似于“03 February”的内容,即使存在 setlocale(LC_ALL, 'it_IT'); 也是如此。有什么错误?如何以意大利语输出日期? 系统:PHP 5.4.11 和 nginx(在 Ubuntu 服务器上)。
编辑:我还运行了 dpkg-reconfigure locales:
Generating locales...
en_US.UTF-8... up-to-date
it_IT.UTF-8... up-to-date
Generation complete.
【问题讨论】:
-
它应该工作:见php.net/manual/en/function.strftime.php。但是文档继续说“您的 C 库可能不支持所有转换说明符,在这种情况下,PHP 的 strftime() 将不支持它们。”
-
嗯.. 所以?我应该怎么办?我应该尝试将 '%d %B' 更改为其他内容吗?无论如何,不支持它们很奇怪..它们非常基本!
标签: php date strtotime setlocale