2009-11-18 88 views
2

我在我的智慧結束與這一個,然後我記得堆棧溢出。PHP-UTF8問題與德國人字符

我有一個網站,http://bridgeserver3.co.uk/disklavier/de/,語言被存儲在一個簡單的PHP文件,它看起來像..

$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."; 

(字符的文件中完全顯示出來,而不是在SO)。

此文本是從excel電子表格導出的,並且是手動創建的平面文件。

網頁編碼是UTF8,我也補充說:

header("Content-type: text/html; charset=UTF-8"); 

到PHP文件,但是當我回聲出字符串時,它失去了德語字符。

任何人都可以提供任何提示嗎?

詹姆斯

+0

你是什麼意思的失去人物? – Gumbo 2009-11-18 16:47:14

+0

如果作爲測試,將翻譯後的文本直接插入到頁面/模板中,這些註釋是否會消失? – 2009-11-18 17:00:28

回答

3

我發現這個問題...

的Excel導出的文本與Windows編碼,所以即使是在TextMate的正確看着我的Mac上。當我重新打開UTF8編碼時,問題在翻譯文件中可見。

解決我在PC上使用EditPadPro轉換爲UTF8。

Phew。

1

也許你可以嘗試添加這是你的<head>標記內?

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

+1

HTTP頭中的聲明具有更高的優先級。 – Gumbo 2009-11-18 16:51:10

1

網頁編碼是UTF8,我也補充說:

大概不會。確保php文件實際上是用utf-8編碼保存的。

0

我使用Coda,但我認爲textmate必須提供一些選項,如Text-> Encoding-> Unicode UTF-8,激活它,然後您的文件將被正確編碼並保存。 無論如何,如果你打算放置一些表格,但你不確定人們使用的是正確的編碼模式,你將會遇到同樣的問題。

使用這樣的事情:

<?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 

?> 

希望這有助於你!

Luis。