If setting charset using meta tag doesn’t seem to work

Been busy those days. But when I came across this problem I couldn’t resist not writing about it because I definitely had it before but always left unresolved … now, finally I know how to solve it 🙂

1. If your file encoding is definitely UTF-8

2. If you definitely have the right version of META tag, that is: <meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″> (note that you don’t necessarily need to close this tag… )

3. If browser still shows page in some encoding but not UTF-8 (by checking in View->Character Encoding menu in a browser)

It means there is only 1 place left to look for, it’s in WebServer 🙂

Solution is simple, while page is being served WebServer, apparently, notifies web browser about what is coming in page headers (you can check it using Firebug)… and in my case it was windows-1251 (Russian). Hence, you will need to modify what your WebServer sends in headers.There are 2 solutions for this:

1. Change settings of your WebServer

2. Change the charset of the page dynamically when it is being served (which is more viable, because usually we don’t have access to the WebServer settings…. or we don’t want to change those settings not to break something else)

Ex: In PHP this is done using “header” function (this should be called before anything else) as follows:

<?php header(‘Content-type: text/html; charset=utf-8’);?>

Leave a comment