Hi fellow developers,

I am having a weird issue on my site. I can't make pages use charset "utf-8"!

Take a look at this simple test page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Document</title>
</head>

<body>

<p>Some Non-Western Characters: å ä ö Å Ä Ö</p>

</body>
</html>

This page should by default be display using Unicode character encoding in the browser, but the browser defaults to ISO-8859-1!! 😕
Yes, the syntax is right! I have been trying this page out on two more servers and it's working nice.
Is there some setting in the php.ini that needs to be changed by the host?

Any help is appreciated! 🙂

    The meta tag for content-type is little more than a fallback. If a content-type header is sent with character encoding specified, this will be used, at least by FF 3.5 and Safari 4.

    Here, the charset of the meta tag will be used.

    <?php
    	header("Content-Type: text/html;");
    ?><!DOCTYPE ...><html ...><head>
    	<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>

    But if you first send this header, it doesn't matter what charset you specify in the meta tag.

    	header("Content-Type: text/html; charset=utf-8");

    Using Safari, Firefox with the firebug plugin, and iirc IE8 as well, you can see what headers were sent by the server.

      Thanks!

      You are right!
      Firebug says server sends this in the header: Content-Type text/html; charset=ISO-8859-1

      But what about html-files not using php? And why is the charset being sent by the server? It should be possible to change

        NogDog;10927982 wrote:

        This may help.

        Thanks! That's just what I needed. It is still not working though. Changing the charset in the htaccess file causes an internal server error. This must be caused by the apache server not allowing that in an htaccess file. So I will have to deal with the slow support at my host :queasy:

          If worse comes to worst, you can change your .html files to .php and just add the header() call at the top of each file, or if your host permissions allow, set up an auto_prepend_file setting (either in php.ini or .htaccess) that specifies a file which does the header(), automatically executing it at the start of any .php file.

            Write a Reply...