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?

4

1 回答 1

3

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">
于 2013-03-30T21:26:53.050 回答