$con = mysql_connect ("localhost", "root", "1234");
mysql_select_db ("Test", $con);
mysql_query ("Set names UTF8");
mysql_query ("Set Character_set_client=utf8");
mysql_query ("Set Character_set_results=utf8");
$q =mysql_query ("SELECT * from people");
while ($e =mysql_fetch_assoc ($q)) {
$output []= $e; }
Print (Json_encode ($output));
Mysql_close ();
?>
Output Result:
[{"id": "Ten", "Name": "John", "Sex": "1", "Birthyear": "1979"},{"id": "One", "Name:" \u5f20\u4e09 "," Sex ":" 1 "," birthyear ": "1989"}]
Why not Zhang San?
Reply to discussion (solution)
You Json_encode, Chinese?? Not union??
Print (Json_encode ($output));
Change into
Print ($output);
If you want to see Chinese after json_encode, can you? Before you test me? Article: http://blog.csdn.net/fdipzone/article/details/28766357
Json_encode only accepts UTF-8 encoded data.
Json_encode converts multibyte utf-8 characters into two-byte Unicode encoded entity forms when JSON encoding is done
This bouquet in any environment will not cause data distortion due to coding
JSON data format is mainly used for communication with JS, and the browser will convert any encoded data into its working character set Unicode
So, Json_encode's transcoding work helps ease the pressure on the browser.
$con = mysql_connect ("localhost", "root", "1234");
mysql_select_db ("Test", $con);
mysql_query ("Set names UTF8");
mysql_query ("Set Character_set_client=utf8");
mysql_query ("Set Character_set_results=utf8");
$q =mysql_query ("SELECT * from people");
while ($e =mysql_fetch_assoc ($q)) {
$output []= $e; }
Print (Json_encode ($output));
Mysql_close ();
?>
Output Result:
[{"id": "Ten", "Name": "John", "Sex": "1", "Birthyear": "1979"},{"id": "One", "Name:" \u5f20\u4e09 "," Sex ":" 1 "," birthyear ": "1989"}]
Why not Zhang San?
Why did I reload the Wamp, and then become garbled, instead of backwards? Is there a problem with the above code? Or is there a file to configure?
Where do you see garbled characters?
Where do you see garbled characters?
Inexplicably no garbled. It's a decoding problem.
What's the problem with decoding?
What's the problem with decoding?
Thank you moderator, just solved the problem of decoding, in order to make PHP in the browser output time, can display Chinese, I added in front of the echo " "; The original sentence was also received by Android. Is everything printed through PHP sent to the Android client?
Yes, anything PHP prints is sent to the client