2

I have a VPS (Debian, Apache, MySQL, PHP)

I want to force the encoding in UTF-8. I have put this line :

header('Content-type: application/json; charset: UTF-8');

But the charset is still ISO8859

I also edited the php.ini : /etc/php5/apache2/php.ini

mbstring.language=UTF-8
mbstring.internal_encoding= UTF-8
mbstring.http_input=UTF-8
mbstring.http_output=UTF-8
mbstring.detect_order= auto

and the apache conf :

nano /etc/apache2/conf.d/charset
AddDefaultCharset UTF-8

An iOS application is calling my php page. And I give it a JSON output. But it receives ISO charset...

2
  • When you say "the charset is still ISO8859", what do you mean? Where do you see that value? Commented May 25, 2012 at 20:53
  • I look the page information (right button in Firefox) the encoding is ISO. I have a json output. Commented May 25, 2012 at 20:57

3 Answers 3

7

Your response header is incorrect:

header('Content-type: application/json; charset: UTF-8');

It should be:

header('Content-type: application/json; charset=UTF-8');

Notice the = in place of :

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

Comments

3

Did you take a look at the utf8-encode function: http://php.net/manual/en/function.utf8-encode.php ?

You may be echoing non-properly encoded text to the client. Apache does not do this for you.

3 Comments

Yes but when I look the page information (right button in Firefox) the encoding is ISO
Did you check if you have any warning message that could help in the error console?
Oh. Figured it. Your header is wrong, you should have Content-type: application/json; charset=UTF-8 instead of Content-type: application/json; charset: UTF-8.
3

In .htaccess file you can put:

php_value default_charset UTF-8

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.