views:

347

answers:

4

Recently I switched hosting from one provider to the other and I have problems displaying Cyrillic characters. The characters which are read from the database are displayed correctly, but characters which are hardcoded in the php file aren't (they are displayed as question marks).

The files which contain the php source code are saved in utf-8 form. Help anybody?

A: 

Try placing a meta tag indicating the encoding in the head section:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Darin Dimitrov
Meta tag affect nothing. it's HTTP header response for the page encoding
Col. Shrapnel
A: 

The reason for your problem is often accidental re-encoding the script files by a programmer's editor. It isn't a good practice to hardcode strings which rely on encoding in your php files.

Try switching your browser's encoding to find what encoding is used for hardcoded text, it might help you address the issue. Also make sure to send proper http headers for each page:

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

Optionaly you can insert meta tag in you HTML:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Petr Peller
tried both, doesn't work. everything worked flawlessly on previous hosting, so I assume that the problem is something with the php settings of the new provider.
Bogi
A: 

The problem seems quite strange.
What's the form of these question marks? is it black diamonds with questions? Or just plain question marks?
First of all double check if your files are really utf-8 encoded.
Try to add this header to your code (above all output)

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

But I doubt it would help, as your database text already looks good.
Do you have any SET NAMES queries in your code? what charset it set?

Col. Shrapnel
added it, doesn't work. yes, i have set names query it is SET NAMES 'utf8'.
Bogi
@user295502, so your pages arent in utf-8 then
Col. Shrapnel
A: 

It had something to do with the encoding of the php files. The files were created using Windows Notepad and saved with utf-8 encoding.

When I used Notepad2 to open the files, the encoding of the files was "utf-8 with signature". When I changed encoding to "utf-8", the text displayed correctly.

Bogi