PHP: Cyrillic characters not displayed correctly

19,983

Solution 1

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.

Solution 2

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

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Solution 3

My PHP module was exactly with same problem all text was like "?????????????????"

And my code was written with Notepad++. I found the solution for the problem. The problem wasn't in the header charset or meta tag because the browser actually knows that it is the UTF-8 charset. I tried all encodings from the browser and the result was the same so I knew the problem is somewhere else, not in the browser character encoding at all.

I just opened the PHP module with Notepad++ and selected all code. After that in the Encoding menu I selected "Convert to UTF-8." After uploading to the server, everything worked like a charm.

Solution 4

put this after connecting database:

mysql_query("SET NAMES UTF8");

for mysqli

mysqli_query($connecDB,"SET NAMES UTF8");

and in the header of the page:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Solution 5

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 is set?

Share:
19,983
Bogi
Author by

Bogi

Updated on June 04, 2022

Comments

  • Bogi
    Bogi about 2 years

    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?

  • Bogi
    Bogi about 14 years
    added it, doesn't work. yes, i have set names query it is SET NAMES 'utf8'.
  • Bogi
    Bogi about 14 years
    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.
  • Your Common Sense
    Your Common Sense about 14 years
    @user295502, so your pages arent in utf-8 then
  • Usman Rana
    Usman Rana over 7 years
    Nice catch. Worked for me