iso-8859-1 可以显示德语变音符号吗?还是我需要使用 utf-8?
我有一个多语言网站,托管在服务器上,该服务器的字符编码默认设置为 iso-8859-1。
我想我最好让页面使用 utf-8 并包含一个元标记来声明这一点。不幸的是,这个元标记似乎被覆盖,页面默认为 iso-8859。
德语和荷兰语页面中的许多特殊字符无法正确显示。
我是否需要尝试将服务器默认值更改为 utf-8 或其他?也许我可以完全删除服务器默认设置?嗯...真的不知道在这里做什么最好。
任何建议都会很棒!
I have a multi language website that is hosted on a server that appears to have character encoding set to default to iso-8859-1.
I thought I would be best having the pages utf-8 and included a meta tag to declare this. Unfortunately this meta tag seems to get overridden and the page defaults to iso-8859.
Many special characters in the German and Dutch pages are not showing correctly.
Do I need to try and change the server default to utf-8 or something? Maybe I could remove the server default completly? Hmm... really not sure what's best to do here.
Any advice would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当通过 HTTP 提供 HTML 页面时,不使用内容类型的 HTML 元标记。相反,将使用 HTTP 响应中的内容类型标头。您可以在 Net 面板中使用例如 Firebug 来确定内容类型标头。
如何更改此设置取决于您正在使用的编程语言和/或网络服务器,这对于您来说是不清楚的当前的问题。根据您询问历史记录,您似乎正在使用 PHP。在这种情况下,您需要在向响应发出任何字符之前将以下行添加到 PHP 文件中。
另请参阅:
如果您无法更改 HTTP 响应标头,您必须提供有关您正在使用的编程语言和网络服务器的更多详细信息。这样我们就可以为您提供更合适的答案。
如果您想坚持使用 ISO-8859-1,那么您需要确保您的页面也保存为 ISO-8859-1 而不是 UTF-8。否则,当您将 UTF-8 保存的资源显示为 ISO-8859 时,某些字符可能确实会出现 mojibake -1。
The HTML meta tags for the content type are not used when the HTML page is served over HTTP. Instead, the content type header in the HTTP response will be used. You can determine the content type header with for example Firebug, in the Net panel.
How to change this depends on the programming language and/or the webserver which you are using, which is unclear from your current question. As per you question history, you seem to be using PHP. In that case, you need to add the following line to the PHP file, before you emit any character to the response.
See also:
If you're unable to change the HTTP response header, you have to give more detail about the programming language and webserver which you're using. This way we can give you better suited answers.
If you want to stick to ISO-8859-1, then you need to ensure that your pages are saved as ISO-8859-1 as well instead of as UTF-8. Otherwise some characters may indeed go mojibake when you display a UTF-8 saved resource as ISO-8859-1.
有几种可能的解决方案,但最干净的解决方案是正确声明您的字符编码。
当从 HTTP 服务器提供网页时,编码通常不是由 HTML 文件的元标记给出,而是由
Content-type
HTTP 标头给出。网络服务器可能正在发送类似
Content-type: text/html; 的内容charset=ISO-8859-1
,您需要更改它。如何执行此操作取决于网络服务器。
作为补充:是的,iso-8859-1 适用于德语;它适用于所有西欧语言。然而,它缺少一些字符,特别是欧元符号(位于 iso-8859-15 中)。但使用 UTF-8 更好,因为它几乎涵盖了所有语言。
There are several possible solutions, but the cleanest solution would be to properly declare your character encoding.
When serving web pages from an HTTP server, the encoding is normally not given by the meta-tags of the HTML file, but by the
Content-type
HTTP header.The webserver is probably sending something like
Content-type: text/html; charset=ISO-8859-1
, and you need to change that.How to do this depends on the webserver.
As an addition: Yes, iso-8859-1 is fine for German; it will work for all western European languages. It is missing a few characters, however, notably the Euro sign (that is in iso-8859-15). But using UTF-8 is better, as it covers just about every language.
您可以在这篇维基百科文章中查看支持的字符和应涵盖的语言。据了解,德语是完全支持的,荷兰语也几乎是支持的。
这不仅仅是选择正确的字符编码的问题,您还必须使用该编码保存页面。如果您将页面另存为 ISO-8859-1 并使用表明其为 UTF-8 的内容类型,则浏览器将无法正确解码该页面。 ISO-8859-1 和 Unicode 都支持您需要的字符,但您必须确保内容类型与页面的实际保存方式相对应。
You can see the characters supported and the languages that should cover in this Wikipedia article. According to that, German is fully supported and Dutch is almost.
It's not just a matter of selecting the correct character encoding, you also have to save the pages using that encoding. If you save a page as ISO-8859-1 and use a content type that says that it's UTF-8, then it will be decoded incorrectly by the browser. Both ISO-8859-1 and Unicode support the characters you need, but you have to make sure that the content type corresponds to how the pages are actually saved.