1

好的,所以我有一个 PHP 文件,其中包含多个不同语言的文本字符串。对于大多数语言,如法语或西班牙语,我只需输入字符即可。

我遇到的问题是俄语字符。PHP 文件以 UTF-8 编码,我如何确保正确保存俄语字符并在输出网页上正确显示...只是将文本粘贴到 PHP 文件中的情况,还是有一种方法可以保证字符将正确保存到文件中 - 例如可能将其转换为类似 HTML 的符号?

显然我假设最终用户将在他们的网络浏览器中设置正确的编码,我只是想确保我从头到尾都涵盖了所有内容。

我在 Windows 上使用 Notepad++ 来编辑我的 PHP 文件。

谢谢!

4

4 回答 4

2

如果你想告诉浏览器你的编码,把它放在你的<header>标签中:

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

或短版

<meta charset='utf-8'>

这应该足以让俄语字符正确显示在网页上。

于 2013-02-17T23:01:16.373 回答
1

if your doctype is html declare <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> but if your doctype is xhtml then declare <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />.

Never assume that end-user will act correctly during your designs

If you already have some document, edit your document's meta tag for charset declaration and use notepad++ encoding>convert to UTF-8 without BOM, save your document, safely go on with your multilingual structure from now on.

php tag is irrelevant for your question since you don't mention about any database char setting.

于 2013-02-17T23:44:49.160 回答
1

There is no difference between Latin and Cyrillic characters in UTF-8. Both are just byte sequences. Configure your server or PHP script to send Content-Type: text/html;charset=utf, and you are rather safe.

Your editor might have problems when the font you are using does not contain Russian characters. Choose another font then.

And please ignore the <meta> element recommendations. You don't need that: it is useless when your HTTP headers are correct, and maybe harmful if they aren’t.

于 2013-02-17T23:47:54.883 回答
0

那么你必须检查两件事

  • 为了确保 *.php 是一个 UTF-8 文件,我使用PSPad。如果文件不是 UTF-8 格式,我会这样保存:http ://stepolabs.com/upload/utf-8.png
  • <meta>那么你的网站标签中必须有 UTF-8 编码;

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

    ...更多关于元标记

最后,如果一切都做得很好 - (格式和元声明)都应该正确显示!

于 2013-02-17T23:04:53.353 回答