views:

336

answers:

4

Hello,

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 gehšren bereits zahlreiche Lieder und das Angebot lŠsst 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 revolutionŠre ãPianoSmartªÓ-Funktion fŸr die Synchronisation Ihrer Klavieraufzeichnungen mit handelsŸblichen Audio-CDs. Und wenn Sie schon eine Weile davon trŠumen, eines Tages zumindest passabel Klavier spielen zu kšnnen, hilft Ihnen die neue ãSmartKeyªÓ-Technologie beim Einstudieren Ihrer ersten StŸcke 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

+1  A: 

Maybe you could try adding this inside your <head> tag?

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

jkndrkn
The declaration in the HTTP header has a higher priority.
Gumbo
+3  A: 

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.

FearMediocrity
+1  A: 

The page encoding is UTF8, and I've added:

Probably not. Make sure that the php file is actually saved with utf-8 encoding.

troelskn
A: 

Hi.. 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.

Luis