Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will iso-8859-1 display german umlauts ok or do I need to use utf-8?

I have a multi language website that is hosted on a server that appears to have character encoding set to default to iso-8859-1.

I thought I would be best having the pages utf-8 and included a meta tag to declare this. Unfortunately this meta tag seems to get overridden and the page defaults to iso-8859.

Many special characters in the German and Dutch pages are not showing correctly.

Do I need to try and change the server default to utf-8 or something? Maybe I could remove the server default completly? Hmm... really not sure what's best to do here.

Any advice would be great!

like image 870
ade123 Avatar asked Jan 20 '23 19:01

ade123


2 Answers

The HTML meta tags for the content type are not used when the HTML page is served over HTTP. Instead, the content type header in the HTTP response will be used. You can determine the content type header with for example Firebug, in the Net panel.

alt text

How to change this depends on the programming language and/or the webserver which you are using, which is unclear from your current question. As per you question history, you seem to be using PHP. In that case, you need to add the following line to the PHP file, before you emit any character to the response.

header('Content-Type: text/html; charset=UTF-8');

See also:

  • PHP UTF-8 cheatsheet

If you're unable to change the HTTP response header, you have to give more detail about the programming language and webserver which you're using. This way we can give you better suited answers.

If you want to stick to ISO-8859-1, then you need to ensure that your pages are saved as ISO-8859-1 as well instead of as UTF-8. Otherwise some characters may indeed go mojibake when you display a UTF-8 saved resource as ISO-8859-1.

like image 88
BalusC Avatar answered Jan 30 '23 08:01

BalusC


There are several possible solutions, but the cleanest solution would be to properly declare your character encoding.

When serving web pages from an HTTP server, the encoding is normally not given by the meta-tags of the HTML file, but by the Content-type HTTP header.

The webserver is probably sending something like Content-type: text/html; charset=ISO-8859-1, and you need to change that.

How to do this depends on the webserver.

As an addition: Yes, iso-8859-1 is fine for German; it will work for all western European languages. It is missing a few characters, however, notably the Euro sign (that is in iso-8859-15). But using UTF-8 is better, as it covers just about every language.

like image 23
sleske Avatar answered Jan 30 '23 08:01

sleske