CSS ISO-8859-1 与 UTF-8?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1893946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ISO-8859-1 vs UTF-8?
提问by Jitendra Vyas
What should be used and when ? or is it always better to use UTF-8 always? or ISO-8859-1 still has importance in specific conditions?
应该使用什么以及何时使用?还是总是使用 UTF-8 总是更好?或者 ISO-8859-1 在特定条件下仍然很重要?
Is Character-set related to geographic region?
字符集与地理区域有关吗?
Edit:
编辑:
Is there any benefit to put this code @charset "utf-8";
放这段代码有什么好处 @charset "utf-8";
or like this <link type="text/css; charset=utf-8" rel="stylesheet" href=".." />
或者像这样 <link type="text/css; charset=utf-8" rel="stylesheet" href=".." />
at the top of CSS file?
在 CSS 文件的顶部?
I found for this
我为此找到了
If DreamWeaver adds the tag when you add embedded style to the document, that is a bug in DreamWeaver. From the W3C FAQ:
"For style declarations embedded in a document, @charset rules are not needed and must not be used."
The charset specification is a part of CSS since version 2.0 (may 1998), so if you have a charset specification in a CSS file and Safari can't handle it, that's a bug in Safari.
如果 DreamWeaver 在您向文档中添加嵌入样式时添加了标签,则这是 DreamWeaver 中的一个错误。来自 W3C 常见问题解答:
“对于嵌入在文档中的样式声明,不需要也不得使用 @charset 规则。”
自 2.0 版(1998 年 5 月)以来,字符集规范是 CSS 的一部分,因此如果您在 CSS 文件中有字符集规范而 Safari 无法处理它,那么这就是 Safari 中的错误。
and add accept-charsetin form
并在表单中添加接受字符集
<form action="/action" method="post" accept-charset="utf-8">
and what should be use if i use xhtml doctype
如果我使用 xhtml doctype 应该使用什么
<?xml version="1.0" encoding="UTF-8"?>
or
或者
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
回答by nes1983
Unicode is taking over and has already surpassed all others. I suggest you hop on the train right now.
Unicode 正在接管并且已经超越了所有其他的。我建议你现在就跳上火车。
Note that there are several flavors of unicode. Joel Spolsky gives an overview.
请注意,Unicode 有多种风格。Joel Spolsky 进行了概述。
(Graph current as of Feb. 2012, see comment below for more exact values.)
(截至2012 年 2 月的当前图表,有关更准确的值,请参阅下面的评论。)
回答by Tor Valamo
UTF-8 is supported everywhere on the web. Only in specific applications is it not. You should always use utf-8 if you can.
网络上到处都支持 UTF-8。只有在特定的应用程序中才不是。如果可以,您应该始终使用 utf-8。
The downside is that for languages such as chinese, utf-8 takes more space than, say, utf-16. But if you don't plan on going chinese, or even if you do go chinese then utf-8 is fine.
缺点是对于中文等语言,utf-8 比 utf-16 占用更多空间。但是,如果您不打算使用中文,或者即使您确实使用中文,那么 utf-8 也可以。
The only cons against using utf-8 is that it takes more space compared to various encodings, but compared to western languages it takes almost no extra space at all, except for very special characters, and those extra bytes you can live with. We are in 2009 after all. ;)
反对使用 utf-8 的唯一缺点是与各种编码相比它需要更多的空间,但与西方语言相比,它几乎不需要额外的空间,除了非常特殊的字符,以及那些你可以忍受的额外字节。毕竟我们是在 2009 年。;)
回答by BalusC
If you want world domination, use UTF-8
all the way, because this covers every human character available at the world, including Asian, Cyrillic, Hebrew, Arabic, Greek and so on, while ISO-8859
is only restricted to Latin characters. You don't want to have Mojibake.
如果你想统治世界,就一直使用UTF-8
,因为这涵盖了世界上所有可用的人类字符,包括亚洲、西里尔文、希伯来文、阿拉伯文、希腊文等,而ISO-8859
仅限于拉丁文字符。你不想有Mojibake。
回答by RationalRabbit
I find iso-8859-1 very useful on a couple of sites where I have clients sending me text files that were created in Word or Publisher, that I can easily insert into the midst of PHP code and not worry about it - especially where quotes are concerned. These are local, U.S. companies, there is literally no other difference in the text on the pages, and I see no disadvantage in using that character set on those particular pages. All others are UTF-8.
我发现 iso-8859-1 在几个站点上非常有用,我有客户向我发送在 Word 或 Publisher 中创建的文本文件,我可以轻松地将其插入到 PHP 代码中而不必担心 - 特别是在引号中关心。这些是本地的美国公司,页面上的文字实际上没有其他区别,我认为在这些特定页面上使用该字符集没有任何缺点。所有其他都是UTF-8。
回答by Chris Becke
ISO-8859-1 is a great encoding to use when space is a premium and you are only ever going to want to encode characters from the basic latin languages it supports. And you are never ever ever going to ever have to ever contemplate ever upgrading your application to support non latin languages.
utf8 is a fantastic way to (a) use the large code base of 8bits per character code libraries there are that already exist, or (b) be a euro snob. utf8 encodes standard ascii in 1 byte per character, latin 1 in 2 bytes per character, eastern european and asian languages get 3 bytes per character. It possibly goes up to 4 bytes per character if you start trying to encode ancient languages that dont exist in the basic multilingual plane.
utf16 is a great way to start a new codebase from scratch. Its completely culture neutral - everone gets a fair handed 2 bytes per character. It does need 4 bytes per character for ancient/exotic languages - which means - in the worst case - its as bad as its big brother:
utf32 is a waste of space.
ISO-8859-1 是一种很好的编码,当空间非常宝贵并且您只想对它支持的基本拉丁语言中的字符进行编码时,可以使用它。而且您永远不必考虑升级您的应用程序以支持非拉丁语言。
utf8 是 (a) 使用现有的每个字符 8 位代码库的大型代码库的绝妙方法,或者 (b) 成为欧元势利小人。utf8 将标准 ascii 编码为每个字符 1 个字节,拉丁语 1 in 2 个字节每个字符,东欧和亚洲语言每个字符获得 3 个字节。如果您开始尝试对基本多语言平面中不存在的古代语言进行编码,则每个字符可能会增加到 4 个字节。
utf16 是从头开始新代码库的好方法。它完全是文化中立的——每个角色都得到公平对待的 2 个字节。对于古代/异国语言,每个字符确实需要 4 个字节 - 这意味着 - 在最坏的情况下 - 它和它的大哥一样糟糕:
utf32 浪费空间。