简体   繁体   English

.php 网页中的西里尔字符混乱

[英]Cyrillic characters messed up in .php webpage

All my files with .php extension and Cyrillic encoding that worked fine for years got messed up.我所有带有 .php 扩展名和 Cyrillic 编码的文件都可以正常工作多年,但都搞砸了。 Probably because of PHP server upgrade by hosting provider.可能是因为托管服务提供商升级了 PHP 服务器。

To illustrate the problem I wrote the simplest possible file which cannot have any errors: http://reverent.org/testencoding.php为了说明这个问题,我写了一个最简单的文件,它不会有任何错误: http : //reverent.org/testencoding.php

For some reason webpage defaults to unicode when viewed in a browser.出于某种原因,网页在浏览器中查看时默认为 unicode。 If you go to view -> Text encoding and select Cyrillic(Windows) everything gets fine.如果你去查看 -> 文本编码并选择 Cyrillic(Windows) 一切都会好起来的。

In contrast, exactly the same file with .html extension is displayed correctly right away: http://reverent.org/testencoding.html相反,具有 .html 扩展名的完全相同的文件会立即正确显示: 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.我的问题是我在服务器上的文件默认设置为 windows 1251 而不是 UTF-8,这是我需要的。类似的东西。 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.我通过使用 WinSCP 访问文件并手动将文件切换到 UTF-8 来修复它……具有讽刺意味的是,您的文件几乎显示了我在我的网站上看到的内容。

在此处输入图片说明

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):必须有比 WinSCP 更好的方法来做到这一点,但老实说,这是我唯一一次必须手动执行此操作,所以这正是我在那里单击的(打开文件后):

在此处输入图片说明

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.我只是将带有这一行 'default_charset = "windows-1251"' 的 php.ini 文件放在带有 Cyrillic 编码文件的目录中。 This overwrites server's php.ini which sets default charset to UTF.这会覆盖服务器的 php.ini,它将默认字符集设置为 UTF。 Now everything is fine: http://reverent.org/ru/testencoding.php现在一切都很好: http : //reverent.org/ru/testencoding.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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