波兰人字符utf8不显示正确 [英] polish characters utf8 dont show right

查看:128
本文介绍了波兰人字符utf8不显示正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我的网站支持英语,葡萄牙语,瑞典语和波兰语。但由于某些原因,一些波兰语字符不能正确显示,例如Zal zkonto 它应该看起来像这样Zalózkonto



我有这个

  //发送Content-type头如果web服务器设置为发送其他内容
header('Content-type:text / html; charset = utf-8');

和内部< head> p>

 < meta http-equiv =content-typecontent =text / html; charset = utf-8/> 


解决方案

您还需要将字符串转换为UTF8。 / p>

utf8_encode()不检查你的字符串是什么编码,有时会给你一个乱码的字符串,所以我做了一个叫Encoding :: toUTF8()的函数来这样做是正确的。



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



我这样做是因为一个服务给我提供了所有乱七八糟的数据,混合了这些编码

用法:

  $ utf8_string =编码:: toUTF8 ($ mixed_string); 

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

我已经包含另一个函数Encoding :: fixUTF8(),它将修复每个UTF8字符串看起来乱码已被多次编码为UTF8的产品。

用法:

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

示例:

  echo Encoding :: fixUTF8(Fédé口Camerounaise de Football); 
echo Encoding :: fixUTF8(Fé©dé©Camerounaise de Football);
echo Encoding :: fixUTF8(Fé©©dé©©卡梅奥纳塞德足球);
echo Encoding :: fixUTF8(FéderationCamerounaise de Football);

会输出:

 足球锦标赛
足球锦标赛
足球锦标赛
Camerounaise de Football

下载:

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


Currently my site supports English, portuguese, swedish and polish. But for some reason some polish characters dont show right, like Zal�z konto it should look like this Zalóz konto

I have this

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

and inside <head>

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

解决方案

You need to convert your string to UTF8 also.

utf8_encode() does not check what encoding your string was in, and sometimes it gives you a messed up string, so I made a function called Encoding::toUTF8() to do this right.

You dont need to know what the encoding of your strings is. It can be Latin1 (iso 8859-1), Windows-1252 or UTF8, or the string can have a mix of them. Encoding::toUTF8() will convert everything to UTF8.

I did it because a service was giving me a feed of data all messed up, mixing those encodings in the same string.

Usage:

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

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

I've included another function, Encoding::fixUTF8(), wich will fix every UTF8 string that looks garbled product of having been encoded into UTF8 multiple times.

Usage:

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

Examples:

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");

will output:

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

Download:

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

这篇关于波兰人字符utf8不显示正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆