6

I have code:

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

In some languages I get:

2012 junio 3, domingo

I want that first letter of all words would be uppercase (capital), so it would look like:

2012 Junio 3, Domingo

I didn't find any answer in internet, does anybody have an idea? :)

user1384668
  • 127
  • 2
  • 3
  • 11

5 Answers5

16

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

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

Simone
  • 20,302
  • 14
  • 79
  • 103
5
echo ucwords(strftime("%Y %B %e, %A"));
Mitya
  • 33,629
  • 9
  • 60
  • 107
  • 1
    Given that `strftime()` provides a localised date string, and some localisations use multi-byte character sets, it would be wise to take that into account. See http://stackoverflow.com/questions/2517947/ucfirst-function-for-multibyte-character-encodings for an example of how to write a multi-byte-characterset-safe ucfirst() function. – Spudley Jun 03 '12 at 22:29
2

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

Gavriel
  • 18,880
  • 12
  • 68
  • 105
1

Try styling the output like this:

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

or

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

This way you can choose which words to capitalize. In your case ucwords works I guess, since you want all your words starting with uppercase.

hug
  • 1,169
  • 10
  • 7
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 > 
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223