Thursday, November 8, 2007

Naming dates (not in english)

It is very common to the problem of wanting to put "November 8, 2007" in a language different from english... In general, a switch is used to translate the name of the month, but there is a much simpler way to do it. PHP brings the ability to configure the location, and then select "regional" settings like language, currency, numbers.

To do so, we must first set the region with setlocale and then we can use the date format with strftime

Example
setlocale(LC_ALL, 'sp');
echo strftime('%d de %B de %Y');
?>

No comments: