PHP read data from MySQL output garbled MySQL: PHP file: & lt; html & gt; & lt; head & gt; & lt; meta & nbsp; charsetutf-8 & nbsp; & gt; & lt ;? Phpheader (Content-Type: & nbsp; texthtml; & nbsp; charsetutf-8); $ index & nbsp; PHP read data output garbled from MySQL
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.
------ Solution --------------------
This is not garbled. this is encrypted in json format. if you want to view it, decrypt it when outputting it.
------ Solution --------------------
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.