开发者

How to get € to appear correctly on a web page?

开发者 https://www.devze.com 2023-02-20 06:38 出处:网络
The euro € symbols in the footer of this page are not displaying correctly http://fundcentre.newireland开发者_开发问答.ie/

The euro symbols in the footer of this page are not displaying correctly

http://fundcentre.newireland开发者_开发问答.ie/

What is the best way to correct this?

Edit: this html is supplied by a 3rd party. We take it, wrap it around our content, and render the page

Edit Again: just looking at the code, I can see that we read the 3rd party HTML into our solution with the following:

wrapperHtml = System.IO.File.ReadAllText(sWrapperLocation, Encoding.GetEncoding("iso-8859-1")); .. So we're reading it as one encoding and rendering it as the other..


This looks like UTF-8 data that was somehow interpreted in a ISO-8859-1 context (or some other single byte encoding). Whatever you use to read the 3rd party source may be incorrectly interpreting the data as single-byte while it in fact is UTF-8.

This is about everything that can be said without knowing more about your setup.

Edit: Why fixing this by using entities is a bad idea, copied from my comment:

The problem is not limited to the Euro character, but applies to all characters outside the ISO-8859-1 range. That means that while you can happily replace the € by € without any real damage, the instant a chinese or cyrillic character comes up in your data, you'll have no entity to convert it to. You would have to convert perfectly healthy UTF-8 content into their numeric entities in real time just to avoid having to fix the encoding problem. That is just insane.


€ is the entity you are looking for


Use HTML encoding; to get a € type a €


You are using:

wrapperHtml = System.IO.File.ReadAllText(sWrapperLocation, Encoding.GetEncoding("iso-8859-1"));

Try changing it to:

wrapperHtml = System.IO.File.ReadAllText(sWrapperLocation, System.Text.UTF8Encoding);

That should keep the multi-byte characters correctly.

Edit: Also you could just remove the second argument all together as that will keep the original encoding regardless of what it was.

Update: I know its evil, but try this. If it works, the encoding issue is on your end, somewhere, if it doesn't work the encoding issue is with the file or where you get the file.

wrapperHtml = HttpUtility.HtmlEncode(System.IO.File.ReadAllText(sWrapperLocation));

The above line will trap and encode the multi-byte and single byte characters that need to be for html encoding. For the moment it will take encoding issues off the plate if they are in your code (after this line), with the server, with the transport or with the browser, with the doc types and a lot of other things. If it works, you know the file is in a valid format and your encoding issues are somewhere after the file and you reading in the file.


Use HTML code : € or €

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号