0

I have a string stored in the database as: Nüguns, and when I do a print_r I get this:

array (
     [0] => N�guns
)

Then when I do json_encode, the value becomes null

Is there something I need to do in order for json to encode it correctly?

3
  • have you set charset for databae? Commented Mar 30, 2013 at 21:22
  • character set connection: utf8, character set results: utf8 Commented Mar 30, 2013 at 21:24
  • use this , mysql_query("SET NAMES utf8"); Commented Mar 30, 2013 at 21:28

1 Answer 1

1

You need to check the following:

1- set character encoding while connecting to database by adding this after you select the database:

mysql_query("SET NAMES UTF8")

or

$mysqli->set_charset("utf8")

2- Add UTF-8 as header, you can use

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

or using just HTML

<meta charset="UTF-8">
Sign up to request clarification or add additional context in comments.

3 Comments

Perfect it was the query part! Thanks!
Never set the charset via SET NAMES, use mysqli_set_charset instead.
Thanks @nkr I added your suggestion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.