In a HTML file with charset=utf-8, do I still need to replace umlauts with ä?

走远了吗. 提交于 2019-12-09 14:04:20

问题


Whenever I used a German umlaut in a HTML file in the past, always I replaced it by ä, ö etc. according to this table.

I had no idea about encoding then, nor did I ever think about it.
I just "knew" that when I would just use ä, ö etc. instead, many computers in other countries wouldn't be able to display the umlauts correctly.

When I set the charset of an UTF-8 encoded HTML file to UTF-8 by putting <meta charset="utf-8"> into the header, do I still need to replace ä by &auml;, ö by &ouml; and so on?

For example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>ÄÖÜäöüß</title>
  </head>
  <body>
    ÄÖÜäöüß
  </body>
</html>

When I save this in an UTF-8 encoded HTML file on my machine and view it in a browser, all umlauts are displayed correctly.
But I'm in Germany and everything on my machine is in German, so of course my machine is able to properly display German umlauts.

I read Joel's The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!), but this encoding stuff is all new to me.

From what I understand about encoding, UTF-8 and setting charsets, I'm suspecting that setting <meta charset="utf-8"> in an UTF-8 encoded HTML file means I do not need to use &auml; etc. anymore.
But I couldn't find a source that definitely says so.


回答1:


When I set the charset of a HTML file to UTF-8 by putting <meta charset="utf-8"> into the header

That doesn't set the character encoding. It declares which character encoding you are using. You must also make sure you are saving the HTML using that encoding.

Given that then:

do I still need to replace ä by &auml;, ö by &ouml; and so on?

No. Only characters with special meaning in HTML (<, >, &, ", ' … all of which only have special meaning in some contexts) must be replaced with character references.



来源:https://stackoverflow.com/questions/22443288/in-a-html-file-with-charset-utf-8-do-i-still-need-to-replace-umlauts-with-auml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!