Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Japanese characters on a php page?

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.

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.

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?

Thanks

like image 517
AndreLiem Avatar asked Dec 14 '22 05:12

AndreLiem


2 Answers

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 Header is sent in UTF-8
  2. Meta tag is set to UTF-8 (Content-Type)
  3. Storage is set to UTF-8
  4. Server output is set to UTF-8

That seems to work for me. Hope this helps.

like image 147
Kieran Hall Avatar answered Dec 19 '22 09:12

Kieran Hall


You have to deliver the documents with the proper encoding declaration in the HTTP header field Content-Type.

In PHP you do this via the header function before the first data has been send to the client, so preferably as one of the first statements:

<?php
    header('Content-Type: text/html;charset=utf-8');

    // the rest
like image 36
Gumbo Avatar answered Dec 19 '22 09:12

Gumbo