【问题标题】:setlocale(LC_ALL, 'it_IT'); set, but still dates in englishsetlocale(LC_ALL, 'it_IT');已设置,但仍为英文日期
【发布时间】: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


【解决方案1】:

听起来很傻,但我解决了将行更改为:

<?php setlocale(LC_ALL, 'it_IT.UTF-8'); ?> 

【讨论】:

  • 是的,我要等 2 天。 :)
  • 在网上搜索了 2 个小时后,我终于想放弃了,然后我点击了一个将我带到这里的链接,当我看到你的回答 @MultiformeIngegno 时,它就点击了。我尝试了一切,但我忘记在 UTF 和 8 之间写“-”。当我看到你的答案时,我只知道“-”会成功。 id 做到了。非常感谢。
  • 在所有视图中使用字符串替换要好得多。谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-01-28
  • 2012-03-18
  • 1970-01-01
  • 2014-10-28
  • 1970-01-01
  • 1970-01-01
  • 2019-12-05
  • 2011-12-20
相关资源
最近更新 更多