Reputation: 1672
I'm at my wits end with this one, then I remember stack overflow.
I have a site, http://bridgeserver3.co.uk/disklavier/de/ , the language is stored in a simple PHP file which looks like..
$translations["welcome_text_3"]="Zum Lieferumfang eines jeden Disklaviers gehren bereits zahlreiche Lieder und das Angebot lsst sich jederzeit erweitern. Unsere neuen Modelle warten sowohl mit akustischen als auch mit digitalen Errungenschaften auf, darunter die Wiedergabe von Audio- und MIDI-CDs sowie die revolutionre ãPianoSmartªÓ-Funktion fr die Synchronisation Ihrer Klavieraufzeichnungen mit handelsblichen Audio-CDs. Und wenn Sie schon eine Weile davon trumen, eines Tages zumindest passabel Klavier spielen zu knnen, hilft Ihnen die neue ãSmartKeyªÓ-Technologie beim Einstudieren Ihrer ersten Stcke und versieht Ihr Spiel sogar mit professionellen Verzierungen.";
(The characters show up perfectly in the file, but not on SO).
This text was exported from an excel spreadsheet and the flat file created manually.
The page encoding is UTF8, and I've added:
header("Content-type: text/html; charset=UTF-8");
to the php file, yet when I echo out the string it lose the German characters.
Can anyone offer any tips?
James
Upvotes: 2
Views: 9582
Reputation: 313
I use Coda but I think textmate has to offer some option like Text->Encoding->Unicode UTF-8, activate it and then your file will be encoded properly and then save it. Anyway if you are going to put some forms and you are not sure the people is using the correct encoding mode you'll have the same problem.
Use something like this:
<?php
$not_utf8 = "An invalid string"; //Put here the bad text for testing
$not_utf8 = mb_convert_encoding($not_utf8, 'UTF-8', mb_detect_encoding($not_utf8));
echo htmlspecialchars($not_utf8, ENT_QUOTES, 'UTF-8'); //The output should be ok, see the source code generated and search for the correct html entities for these special chars
?>
Hope this help you!
Luis.
Upvotes: 2
Reputation: 117447
The page encoding is UTF8, and I've added:
Probably not. Make sure that the php file is actually saved with utf-8 encoding.
Upvotes: 1
Reputation: 1672
I found the problem...
Excel exported the text with Windows encoding, so it looked correct even in TextMate on my mac. When I reopen with UTF8 encoding the problem was visible in the translations file.
To resolve I used EditPadPro on a PC to convert to UTF8.
Phew.
Upvotes: 3
Reputation: 4062
Maybe you could try adding this inside your <head>
tag?
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Upvotes: 2