PHP reads data from MySQL and outputs garbled MySQL:
The PHP file is as follows:
Header ("Content-Type: text/html; charset = utf-8 ");
$ Index = 0;
$ Con = mysql_connect ("localhost", "root ","");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}
Mysql_select_db ("test", $ con );
Mysql_query ("set names 'utf8 '");
Mysql_query ("set character_set_client = utf8 ");
Mysql_query ("set character_set_results = utf8 ");
$ Result = mysql_query ("SELECT * FROM test_list
Limit 0, 4 ");
While ($ row = mysql_fetch_array ($ result ))
{
$ Load_crouse_array [$ index] = array (
'Subject _ id' => $ row ['subject _ id'],
'Subject _ title' => $ row ['subject _ title'],
'Subject _ url' => $ row ['subject _ url'],
'Subject _ belong '=> $ row ['subject _ belong'],
'Creat _ time' => $ row ['creat _ time']
);
$ Index ++;
}
Mysql_query ("insert into 'test '. 'test _ list' ('subject _ id', 'subject _ title', 'subject _ url', 'subject _ belong ', 'creat _ time ') VALUES ('20140901', 'Test text', 'Test _ url', 'Excel _ crous', '2017-08-10 ');");
Echo json_encode ($ load_crouse_array );
Echo "test Chinese ";
?>
Final output result:
At the same time, the inserted records are displayed as ??? in the Chinese part of the database ????.
This problem occurs when I use Eclipse programming and then directly use the text editing software Notepad ++. The environment is Windows 7, XMAPP, and chrome browser is used.
Reply to discussion (solution)
Ask the forum experts to help you see where the problem occurs. Why are Chinese characters always garbled. Thank you here.
This is not garbled. this is encrypted in json format. if you want to view it, decrypt it when outputting it.
The data processed by your $ load_crouse_array array after json_encode is not garbled, but unicode processing of Chinese characters.
Output print_r ($ load_crouse_array); you can check whether the code is garbled.
The data processed by your $ load_crouse_array array after json_encode is not garbled, but unicode processing of Chinese characters.
Output print_r ($ load_crouse_array); you can check whether the code is garbled.
Thank you for your help.
This is not garbled. this is encrypted in json format. if you want to view it, decrypt it when outputting it.
Thank you again.
Closed