HTML和字符编码与HTML实体 [英] HTML and character encoding vs HTML Entity

查看:181
本文介绍了HTML和字符编码与HTML实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写HTML文档时,可以使用直接特殊字符,例如下面作为常规文本的字体C的字母C:Ç或使用此实体名称& Ccedil c $ c>?



我已经看到两者都在实践中使用,但肯定有规则控制这个的适当用法, 。例如,此网站维护此字符的原始形式,但其他网站可能最终将其作为方块显示。

解决方案

p>这一切都取决于文档的字符编码。如果您不确定是否应使用常规文字或编码版本,可以通过运行您的网页W3C Validator



请考虑此代码:

 < html& 
< head>
< meta http-equiv =content-typecontent =text / html; charset = utf-8/>
< title> Stuff< / title>
< / head>
< body>
< p>©< / p>
< p>&#169;< / p>
< / body>
< / html>

文档编码设置为UTF-8,验证时,它返回错误:


When writing an HTML document, is it acceptable to use the direct special character such as the captial letter C with a cedilla underneath as regular text: Ç or to use the HTML Entity name of this charecter, &Ccedil ?

I have seen both being used in practice, but surely there are rules governing the appropriate usage of this, as well as advantages to one way over another. For instance, this website maintains the raw-form of this character, but other websites may end up rendering it as a square block.

解决方案

It all depends on the character encoding of the document. If you're unsure of whether or not you should use the the regular text or the encoding version, you could run your page through the W3C Validator.

Consider this code:

<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Stuff</title>
</head>
<body>
 <p>©</p>
 <p>&#169;</p>
</body>
</html>

The document encoding is set to UTF-8 and when it's validated, it returns an error:

Sorry, I am unable to validate this document because on line 7 it contained one or more bytes that I cannot interpret as utf-8 (in other words, the bytes found are not valid values in the specified Character Encoding). Please check both the content of the file and the character encoding indication.

这篇关于HTML和字符编码与HTML实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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