How to display japanese characters on php page?

I am trying to display Japanese characters on a PHP page. No download from the database, just saved in the language file and not done.

I got confused by a weird scenario. I set up the page correctly with UTF-8 and I am testing a sample page on my local WAMP server and it works.

At the moment when I tested our development and production servers, the characters are not displayed properly.

This makes me believe that this is a setting in php.ini. But I did not find much information about this, so I am not sure if this is a problem.

Is there something fundamental that I'm missing?

thanks

+4
source share
4 answers

Since you stated that it works in your development environment and not in your life, you can check the Apache AddDefaultCharset and set this to UTF-8 if it has not already been.

I try to follow these steps:

  • PHP header sent to UTF-8
  • Meta tag set to UTF-8 (Content-Type)
  • Storage installed on UTF-8
  • Server output set to UTF-8

It looks like me. Hope this helps.

+6
source

You must provide documents with the proper encoding declaration in the HTTP Content-Type header field .

In PHP, you do this with the header function before the first data is sent to the client, so it is preferable that one of the first statements is:

 <?php header('Content-Type: text/html;charset=utf-8'); // the rest 
+6
source

First, I assume the same client computer is used for both tests.

So, use Firebug or your tool to select the headers of the HTTP response on the local server and compare them with the headers generated by other servers. You will surely find the difference.

Usually your server should include a header similar to this in the response:

 Content-Type: text/html; charset=UTF-8 

If the headers on the two systems look almost the same, take the body of both answers and load it in a hex editor and find the differences in encoding.

+1
source

Try the following (worked for me, CentOS 6.8, PHP 5.6)

# 1
Apache configuration

/etc/httpd/conf/httpd.conf
AddDefaultCharset UTF-8

# 2
PHP configuration

/etc/php.ini:
default_charset = "utf-8" → default_charset = "Shift_JIS"

Note: set error_reporting = E_ALL and ~ E_DEPRECATED and ~ E_STRICT

# 3
html head meta p>

http-equiv = "content-type" content = "text / html; charset = Shift_JIS"

0
source

All Articles