This is about wrong display of spelled-out German month names which contain special characters (Umlaut, basically only the letter "ä" in "März" - German for March). I am trying to display it like "28. März 2012".
This is in Wordpress, BTW. In the header I have the <meta charset="utf-8">
tag. The corresponding template file contains the following line to get the month names in German:
setlocale (LC_ALL, 'de_AT@euro', 'de_AT', 'de', 'ge');
Actually, this code is for "Austrian German", but it shouldn't make a difference for the month of March = März.
For the page I am fetching a string from the database which represents a date, for example "18.03.2012". Then I convert that string to a "real" PHP date()
:
$date_start = date_create($date_string_from_database);
Since I need to compare that date to another timestamp, I convert it to a timestamp
like this (adding a fixed time of 20:00):
$timestamp_start = strtotime(date_format($date_start, 'Y-m-j 20:00'));
And sometime later I create a formated date with spelled-out German month names from this timestamp like this:
$date_german = strftime("%e. %B %Y", $timestamp_start);
Now, in my localhost installation, this is displayed as expected:
But on the performance server, I get this:
All other special characters (including "ä") on that page are displayed correctly, it must have to do with the way the server handles that strftime
function or the setlocale
settings. FWIW, also the generated HTML code contains that "?" character instead of "ä". The PHP version is 5.6 in both cases.
Any idea what I could do to get it displayed correctly?
EDIT / ADDITION concerning possible duplicate: This has nothing to do with the charset meta tag (which I set, as I described in my question), and also not with encoding/decoding database results. The methos in the accepted answer works well for me, and that solution is not mentioned in the would-be-duplicate.