6

我有代码:

<?php echo strftime("%Y %B %e, %A")?>

在某些语言中,我得到:

2012 年 3 月,多明戈

我希望所有单词的第一个字母都是大写(大写),所以它看起来像:

2012 Junio 3,多明戈

我在网上没有找到任何答案,有人知道吗?:)

4

5 回答 5

16

尝试echo ucwords(strftime("%Y %B %e, %A"));

http://php.net/manual/en/function.ucwords.php

于 2012-06-03T20:09:33.423 回答
5
echo ucwords(strftime("%Y %B %e, %A"));
于 2012-06-03T20:12:05.663 回答
2

ucwords 是你的功能: http: //php.net/manual/en/function.ucwords.php

于 2012-06-03T20:09:23.083 回答
1

尝试像这样设置输出的样式:

strftime('<span style="text-transform: capitalize;">%Y %B %e, %A</span>')

或者

echo '<span style="text-transform: capitalize;">' . strftime('%Y %B %e, %A') . '</span>';

这样您就可以选择要大写的单词。我猜你的情况ucwords是可行的,因为你希望所有的单词都以大写字母开头。

于 2013-10-04T13:58:10.167 回答
0
$ php -a
Interactive shell

php > $x = strftime("%Y %B %e, %A");
php > $str = explode(" ", $x);
php > foreach ($str as $i) { print ucfirst($i) . " "; };
2012 June  3, Sunday 
php > 
于 2012-06-03T20:15:20.287 回答