如何在php页面上显示日文字符?

2022-01-07 00:00:00 unicode character-encoding php

我正在尝试在 PHP 页面上显示日语字符.没有从数据库加载,只是存储在一个语言文件中并被回显.

I'm trying to display Japanese characters on a PHP page. No loading from the database, just stored in a language file and echo'ed out.

我遇到了一个奇怪的场景.我使用 UTF-8 正确设置了页面,并在我的本地 WAMP 服务器上测试了一个示例页面,它可以正常工作.

I'm running into a weird scenario. I have the page properly setup with UTF-8 and I test a sample page on my local WAMP server and it works.

当我测试我们的开发和生产服务器时,字符显示不正确.

The moment I tested it out our development and production servers the characters don't display properly.

这让我相信这是 php.ini 中的一个设置.但是我还没有找到太多关于此的信息,所以我不确定这是否是问题所在.

This leads me to believe then that it's a setting in php.ini. But I haven't found much information about this so I'm not really sure if this is the issue.

是不是我遗漏了一些基本的东西?

Is there something fundamental I'm missing?

谢谢

推荐答案

既然你已经声明它在你的开发环境中工作而不是在你的现场,你可能想检查 Apache 的 AddDefaultCharset 并将其设置为 UTF-8(如果尚未设置).

Since you've stated that it is working in your development environment and not in your live, you might want to check Apache's AddDefaultCharset and set this to UTF-8, if it's not already.

我倾向于确保检查以下步骤

I tend to make sure the following steps are checked

  1. PHP 标头以 UTF-8 格式发送
  2. 元标记设置为 UTF-8(内容类型)
  3. 存储设置为 UTF-8
  4. 服务器输出设置为 UTF-8

这似乎对我有用.希望这会有所帮助.

That seems to work for me. Hope this helps.

相关文章