2

I have a PHP file with one simple echo function:

echo 'アクセスは撥ねりません。';

but when I access that page i get this:

????????????

Can someone help me? I also have my page encoding set to UTF-8, and I know it, because all of the browsers i used said so. I also do this before the echo function:

mb_internal_encoding('UTF-8');

What does this do? Does it help me? All I need is to be able to echo a static Japanese string.

Thanks!

1
  • 1
    Is your file saved as UTF8 as well? If yes, maybe you need other encoding, such as UTF-16? Commented Oct 16, 2009 at 21:35

4 Answers 4

7

There are a few places where this could go wrong.

Firstly, if you aren't setting the output encoding in php with header()

header('Content-type: text/html; charset=utf-8');

or in your html with a meta tag:

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

you will need to check the php.ini setting default_charset. Chances are this is defaulted to iso-8859-1

Secondly, you may also need to check the content encoding you are saving the php script as. If you are saving it as ASCII or some other latin charset, it will munge the characters.

Sign up to request clarification or add additional context in comments.

1 Comment

I am doing all of those things, and it still shows question marks.
1

I got it. I just had to set the mbstring extension settings to handle internal strings in UTF-8. Thas extension is standard with my build of PHP 5.3.0.

Comments

0

Maybe you are printing Japanese characters contained in UTF-16 (extended set of chars)?

Comments

0

I just did a quick test and your example works for me, so it's most likely one of these:

  • Your file is not saved in UTF-8, but some other encoding, such as Shift-JIS. A decent editor should be able to let you see what encoding it used
  • Your server is sending bad http headers. Can you use some tool to check the headers and paste the results? Or the results you got from the browser?
  • The browser is using an incompatible font

I saved a file in UTF-8, pasted your code into it, and my server is serving the file with Content-Type: text/html; charset=utf-8 and it shows up just fine. Did not need to use the mb_ function or anything else.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.