Solving Problems with Character Set (continuously supplemented and updated)

Hi! Users are often faced with the problems of incorrect charset after uploading of websites to our server.

First you need to check the origin of the problem – charset of the file or the database. In principle, it is not difficult to identify. If the entire website is full of incomprehensible gibberish, it is likely a problem is in file charset. This problem can be solved the most easily. By default our server uses utf-8 charset, and in your case, charset of web pages is windows-1251. Let’s create .htaccess file in website folder (or append to the existing one) with the following text:

AddDefaultCharset windows-1251

Then you save it and everything starts working correctly.

That was easy. More difficult problem is when charset of the files is OK, but the problem is with database charset. If you see that part of the text remains readable, but all dynamic information like news, various data, etc. is displayed as question marks, the problem is in the database. How to solve this problem? First you need to make sure that data in the database is in normal form. To do this, go to cpanel and run PHPMYADMIN. Go to the desired database, choose any table with Russian characters and click View. If we see that the text is displayed correctly, then the problem is in charset of database connection with PHP scripts, but if you see question marks here as well, then several options are available.

1. Database dump originally had question marks.
2. Database was uploaded incorrectly.

It is rather easy to check the first option. Open dump in any text editor and see Russian characters there. If you see question marks, then dump is generated incorrectly, and you need to make it again, as the same data cannot be restored. If dump has normal data – most likely an error occurred during uploading. To avoid such problems, we recommend uploading supex.net software DUMPER Lite. It is convenient utility that defines charsets itself. See their website for instructions to work with it.

So, we assume that the database is displayed correctly in PHPMYADMIN, but question marks are displayed on the website (as often happens). To resolve this problem you need to do the following.

For self-written script it is the most easily, as you are its owner, but the rule does not change for any other scripts and engines as well. It’s just harder to find the right line there. So, you need to find the following lines in the script:


    mysql_connect(something);

    mysql_select_db(something);

    Just after these lines, type the following:

    mysql_query("SET NAMES cp1251");


Save it and everything starts working. In the near future we will post recommendations for various engines with information which files and lines to edit. You can send requests to tech support regarding a particular engine.

With love, your Shneider-host.ru. Making the Internet. Inexpensive paid website hosting.