Skip to content Skip to sidebar Skip to footer

While Using Html Entities, It Also Translates Ampersand &

I am working on a ASP.NET MVC multi language web site. When I put for example é to achieve this é, it changes it to é. It seems that it first translates &am

Solution 1:

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.

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.

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:

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

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.

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.

Post a Comment for "While Using Html Entities, It Also Translates Ampersand &"