4

How do I use Unicode with PHP?

I want to store Unicode value in a PHP variable but it output some question marks.

What is the solution?

4
  • 1
    It might be as simple as your browser not displaying the Unicode characters correctly because you have not set utf-8 as the encoding. Commented Feb 9, 2010 at 16:41
  • Unicode is just a standard (see en.wikipedia.org/wiki/Unicode). What exactly do you mean by Unicode? Commented Feb 9, 2010 at 16:41
  • 10
    @Saiful: Accept some questions first. Commented Feb 9, 2010 at 16:42
  • 5
    It is not required to accept answers before asking new questions. But if some of your answers had been satisfactorily answered, please accept the respective answer. Commented Feb 9, 2010 at 16:52

3 Answers 3

8

In php.ini:

default_charset = "UTF-8"
mbstring.internal_encoding = "UTF-8"

; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
mbstring.func_overload = 4
Sign up to request clarification or add additional context in comments.

Comments

4

make sure your output encoding is utf8

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

PS accept some answers.

Comments

3

This is something you're going to have to read up on to do correctly, but here are two links you should start with: Character Sets / Character Encoding Issues Handling UTF-8 with PHP

1 Comment

Thanks, those are very good links! The issue is much more complicated than just setting the header

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.