Home > Software design >  How do I add ucwords() on IntlDateFormatter()?
How do I add ucwords() on IntlDateFormatter()?

Time:05-11

[PHP 8.0] I want to temporary change language just for displaying month as a word. And this works:

$fmt = new \IntlDateFormatter('Fi_FI', NULL, NULL);
$fmt->setPattern('d MMM yyyy'); 
echo $fmt->format(new \DateTime($w_date));

This gives me

10 toukok. 2002

But I want it to say Toukok with uppercase on first letter. So I found out that ucwords() should fix it but I got syntax when I tested

echo $fmt->ucwords(format(new \DateTime($w_date)));

Where and how should I place the ucwords() ? Thanks.

CodePudding user response:

ucwords should surround the whole command, since format is a function of $fmt, while ucwords is a function by itself.

echo ucwords($fmt->format(new \DateTime($w_date)));
  •  Tags:  
  • php
  • Related