如何在 HTML 中正确显示德语字符? [英] How can I properly display German characters in HTML?

查看:36
本文介绍了如何在 HTML 中正确显示德语字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面包含德语字符,并且我在HTML 标记,但浏览器以不同的方式查看某些字符.我是否需要在 HTML 中包含任何内容才能正确显示德语字符?

My pages contain German characters and I have typed the text in between the HTML tag, but the browser views some characters differently. Do I need to include anything in HTML to properly display German characters?

<label> ausgefüllt </label>

推荐答案

对于不幸的是,即使是大多数程序员也无法正确理解的事情,您似乎需要一些基本的解释.

It seems you need some basic explanations about something that unfortunately even most programmers don't understand properly.

像 HTML 页面这样的文件以字节序列的形式在 Internet 上保存和传输,但您希望它们显示为字符.为了将字节转换为字符,您需要一组称为字符编码的规则.不幸的是,历史上出现了许多不同的字符编码来处理不同的语言.它们中的大多数都基于美国 ASCII 编码,但是只要您有 ASCII 之外的字符例如德语变音,您需要非常小心使用哪种编码.

Files like your HTML page are saved and transmitted over the Internet as a sequence of bytes, but you want them displayed as characters. In order to translate bytes into characters, you need a set of rules called a character encoding. Unfortunately, there are many different character encodings that have historically emerged to handle different languages. Most of them are based on the American ASCII encoding, but as soon as you have characters outside of ASCII such as German umlauts, you need to be very careful about which encoding you use.

问题的根源在于,为了正确解码 HTML 文件,浏览器需要知道要使用哪种编码.您可以通过多种方式告诉它:

The source of your problem is that in order to correctly decode an HTML file, the browser needs to know which encoding to use. You can tell it so in several ways:

  • The "Content-Type" HTTP header
  • The HTML META tag
  • The XML encoding attribute if you use XHTML

因此,您需要选择一种编码,使用该编码保存 HTML 文件,并确保您至少以上面列出的一种方式声明该编码(如果您使用了超过一个该死的确保他们同意).至于使用什么编码,德国人通常使用ISO/IEC 8859-15,但 UTF-8 是一个很好的替代方案,可以处理任何类型的非 ASCII 字符同时.

So you need to pick one encoding, save the HTML file using that encoding, and make sure that you declare that encoding in at least one of the ways listed above (and if you use more than one make damn sure they agree). As for what encoding to use, Germans usually use ISO/IEC 8859-15, but UTF-8 is a good alternative that can handle any kind of non-ASCII characters at the same time.

这篇关于如何在 HTML 中正确显示德语字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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