波兰语字符utf8不显示正确

问题描述:

目前我的网站支持英语,葡萄牙语,瑞典语和波兰语。但由于某些原因,一些波兰语字符不显示正确的,像Zal�z konto它应该是这样的Zalóz konto波兰语字符utf8不显示正确

我有这个

// Send the Content-type header in case the web server is setup to send something else 
header('Content-type: text/html; charset=utf-8'); 

和内部<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
+3

从何处得到润色文字?如果来自数据库,则需要在mysql_connect函数之后设置数据库编码。 – antyrat 2010-07-20 15:59:29

+1

你的数据来自哪里?数据库?确保连接设置为UTF-8(MySQL的SET NAMES)。硬编码?确保使用UTF-8编码保存文件。 – igorw 2010-07-20 16:00:08

+0

谢谢!我用utf8 – Remy 2010-07-20 16:24:47

如果检索从MySQL数据数据库与php你应该使用此查询之前做任何事情..

mysql_query("SET NAMES utf8");

因此,从数据库接收到的数据将被正确编码,如果它们被正确地存储在它...

您需要将您的字符串转换为UTF-8也。

utf8_encode()不检查你的字符串是什么编码,有时它会给你一个乱七八糟的字符串,所以我做了一个名为Encoding :: toUTF8()的函数来做到这一点。

你不需要知道你的字符串的编码是什么。它可以是Latin1(iso 8859-1),Windows-1252或UTF8,或者字符串可以混合使用。 Encoding :: toUTF8()会将所有内容转换为UTF8。

我这样做是因为一个服务给我提供了所有乱七八糟的数据,将这些编码混合在同一个字符串中。

用法:

$utf8_string = Encoding::toUTF8($mixed_string); 

$latin1_string = Encoding::toLatin1($mixed_string); 

我已经包含另一个函数,编码:: fixUTF8(),至极将解决所有的UTF8字符串,看起来已经被编码成UTF-8多次出现乱码产品。

用法:

$utf8_string = Encoding::fixUTF8($garbled_utf8_string); 

例子:

echo Encoding::fixUTF8("Fédération Camerounaise de Football"); 
echo Encoding::fixUTF8("Fédération Camerounaise de Football"); 
echo Encoding::fixUTF8("FÃÂédÃÂération Camerounaise de Football"); 
echo Encoding::fixUTF8("Fédération Camerounaise de Football"); 

将输出:

Fédération Camerounaise de Football 
Fédération Camerounaise de Football 
Fédération Camerounaise de Football 
Fédération Camerounaise de Football 

下载:

http://dl.dropbox.com/u/186012/PHP/forceUTF8.zip

+0

保存了这个文件,应该标记为回答 – RCNeil 2012-05-02 17:39:44

或者您可以使用iso-8859-1标准:

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />