简体   繁体   中英

Cyrillic characters messed up in .php webpage

All my files with .php extension and Cyrillic encoding that worked fine for years got messed up. Probably because of PHP server upgrade by hosting provider.

To illustrate the problem I wrote the simplest possible file which cannot have any errors: http://reverent.org/testencoding.php

For some reason webpage defaults to unicode when viewed in a browser. If you go to view -> Text encoding and select Cyrillic(Windows) everything gets fine.

In contrast, exactly the same file with .html extension is displayed correctly right away: http://reverent.org/testencoding.html

Any idea?

Now, I'm no expert on this, but this seriously reminds me of the exact issue I had. So.. personal experience, here goes (I'm sure this might help someone ):

My issue was that my files on the server were set to windows 1251 by default instead of UTF-8, which I needed.. this caused these little beasts to appear: in place of every symbol that wasn't just a basic letter or something like that. Coincidentally this is what your example looks like. And the encoding is the same. I fixed it by accessing the files with WinSCP and just switching the files to UTF-8 manually... ironically your file shows pretty much what I saw on my website.

在此处输入图片说明

There must be better ways to do this than WinSCP, but to be honest, this is the only time I've had to do this manually, so this is exactly what I clicked there (after opening the file):

在此处输入图片说明

You could also try to fix it with a meta tag to tell the browser which charset to use, but the files might be getting deformed the moment you save them, if their encoding is wrong.

<meta charset="utf-8">

This might not work for you, but it did work for me, so there's hope :)

Hope it helps or at least points you in the right direction :)

I just put the php.ini file with this single line 'default_charset = "windows-1251"' in the directory with the files with Cyrillic encoding. This overwrites server's php.ini which sets default charset to UTF. Now everything is fine: http://reverent.org/ru/testencoding.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM