The above is the data in my data inventory, which adopts the utf8_bin encoding. at the beginning, utf8_unicode_ci is used, but still cannot be used. below is my PHP code {code ...} finally, the browser displays the urine {code ...} why is question mark displayed in Chinese? Unicode I want...
The above is the data in my data inventory, which adopts the utf8_bin encoding. at the beginning, utf8_unicode_ci is used, but it still does not work.
Below is my PHP code
Id = $ row ["id"]; $ user-> name = $ row ["name"]; $ user-> address = $ row ["address"]; $ user-> phonenumber = $ row ["phonenumber"]; $ data [] = $ user;} if (function_exists ('MySQL _ set_charset ') = false) {mysql_query ("set names UTF8", $ data);} else {mysql_set_charset ('utf8', $ data);} $ response = array ('code' => 200, 'message' => 'success for request', 'data' => $ data,); echo urldecode (json_encode ($ response )); Mysql_free_result ($ response); // release mysql_close (); // Close the database?>
Finally, the browser displays the urine.
{ "code": 200, "message": "success for request", "data": [ { "id": "100", "name": "??", "address": "????", "phonenumber": "13212340001" }, { "id": "101", "name": "??", "address": "????", "phonenumber": "13512340002" }, { "id": "100", "name": "??", "address": "????", "phonenumber": "13212340001" }, { "id": "101", "name": "??", "address": "????", "phonenumber": "13512340002" }, { "id": "0", "name": "", "address": "", "phonenumber": "0" }, { "id": "103", "name": "??", "address": "????", "phonenumber": "13512340005" }, { "id": "103", "name": "??", "address": "????", "phonenumber": "13512340005" } ]}
Why is question mark displayed in Chinese? I want Unicode encoding.
Reply content:
The above is the data in my data inventory, which adopts the utf8_bin encoding. at the beginning, utf8_unicode_ci is used, but it still does not work.
Below is my PHP code
Id = $ row ["id"]; $ user-> name = $ row ["name"]; $ user-> address = $ row ["address"]; $ user-> phonenumber = $ row ["phonenumber"]; $ data [] = $ user;} if (function_exists ('MySQL _ set_charset ') = false) {mysql_query ("set names UTF8", $ data);} else {mysql_set_charset ('utf8', $ data);} $ response = array ('code' => 200, 'message' => 'success for request', 'data' => $ data,); echo urldecode (json_encode ($ response )); Mysql_free_result ($ response); // release mysql_close (); // Close the database?>
Finally, the browser displays the urine.
{ "code": 200, "message": "success for request", "data": [ { "id": "100", "name": "??", "address": "????", "phonenumber": "13212340001" }, { "id": "101", "name": "??", "address": "????", "phonenumber": "13512340002" }, { "id": "100", "name": "??", "address": "????", "phonenumber": "13212340001" }, { "id": "101", "name": "??", "address": "????", "phonenumber": "13512340002" }, { "id": "0", "name": "", "address": "", "phonenumber": "0" }, { "id": "103", "name": "??", "address": "????", "phonenumber": "13512340005" }, { "id": "103", "name": "??", "address": "????", "phonenumber": "13512340005" } ]}
Why is question mark displayed in Chinese? I want Unicode encoding.
if (function_exists('mysql_set_charset') === false) { mysql_query("SET NAMES UTF8",$data);}else{ mysql_set_charset('utf8',$data);}
This section should be placed inmysql_query
Previously, the second parameter in the other two places should not be$data
But it should be$connect
I have encountered this problem before. just add this question.mysqli_query($conn,"SET NAMES utf8");
class DBHelper{ public function DBHelper(){} private static function getConn(){ $conn = mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_NAME); mysqli_query($conn,"SET NAMES utf8"); return $conn; } public static function opearting($sql){ return mysqli_query(self::getConn(),$sql); }}
The Chinese urlencode encoding problem, which I encountered, cannot be decoded directly. Otherwise, garbled characters may occur. The method I use is.
Separate encoding. Then in decoding ,'/**
* [ReturnUrlencode uses recursion to traverse all arrays and parse them] * @ param [type] $ arr [description] */function ReturnUrlencode ($ arr) {foreach ($ arr as $ key =>$ value) {if (is_array ($ value) {$ arr [$ key] = ReturnUrlencode ($ value );} else {$ arr [$ key] = urlencode ($ value) ;}}return $ arr ;}' # In this way, the output json Chinese characters will not be garbled. Urldecode (json_encode (ReturnUrlencode ($ arr )));
if (function_exists('mysql_set_charset') === false) { mysql_query("SET NAMES UTF8",$data);}else{ mysql_set_charset('utf8',$data);}
This sentence should be placed before traversing data.