在使用HTML实体时,它还会翻译&符号; [英] While using HTML entities, it also translates ampersand &

查看:123
本文介绍了在使用HTML实体时,它还会翻译&符号;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在ASP.NET MVC多语言网站上工作.

I am working on a ASP.NET MVC multi language web site.

例如,当我放置é来实现é时,它将更改为é.

When I put for example é to achieve this é, it changes it to é.

似乎它首先将&转换为&.

出什么问题了?

推荐答案

好的,我想我可能会看到您所指的内容.在文档头部的meta标签中,é更改为é,但是主体中的实体正确.

Ok I think I might see what you are referring to. In the meta tags in the head of your document é is changing to é but the entities in the body are correct.

您可能已经从富文本环境(即rtf或.doc文件)中复制并粘贴了é,它可能包含编码的&符号,而不是纯文本&符号.经验法则-永远不会从诸如单词之类的文本中复制文本,因为它会跨各种不可见的字符进行复制.在为网站准备副本时,请始终以纯文本(.txt)文件格式进行操作,并且您会知道文本是干净的.如果客户端给您提供.doc文件,请先将其转换为.txt,然后再将它们复制到html中,您会看到任何问题.

You have perhaps copied and pasted é from a rich text environment (i.e. an rtf or perhaps a .doc file) and it may contain an encoded ampersand rather than a plain text ampersand. Rule of thumb - never ever ever copy text from something like word as it copies across all sorts of invisible characters. When you prepare copy for your website always do in in plain text (.txt) files and you'll know your text is clean. If a client gives you .doc file convert them to .txt first and you will see any issues before you copy them into the html.

但是,在文档的开头,当属性值中包含文本时,引号之间是什么,例如在描述meta标签的content属性中,就像这样:

However, in the head of your document when you have text in an attribute value, what's between the quotes, for example in the content attribute of the description meta tag, like so:

<meta name="description" content="Enregistreur vocal est une application polyvalente avec un son de haute qualité." />

您不需要使用实体,因为该字符串是纯文本而不是html-因此将其更改为常规é即可使用.

you don't need to use entities because that string is plain text not html - so change it to a normal é and it should work.

注意:以上内容假设meta标记中的字符串不是来自数据库,而是实际上位于html页面中.如果字符串来自数据库,然后放入meta标记中,则您可能已经在asp中使用了诸如HttpContext.Current.Server.HtmlEncode()之类的东西将其首先放置在数据库中-这是问题的根源.如果是这种情况,在将其放入meta标记之前,需要使用HttpContext.Current.Server.Htmldecode()将其转换回纯文本.

Note: The above assumes that the string in the meta tags are not coming from a database but is actually in the html page. If the string is coming from a database and then placed into the meta tags you may have used something like HttpContext.Current.Server.HtmlEncode() in asp to place it in the database in the first place - that's the root of the issue. If this is the case, before you place it in the meta tag you need to use HttpContext.Current.Server.Htmldecode() to convert it back to plain text.

这篇关于在使用HTML实体时,它还会翻译&符号;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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