PHP and web pages use UTF-8 encoding. The database is sql server2008 and uses the default encoding. When reading database data, use the json_encode() that comes with PHP to return to the front end. The results will not be displayed in Chinese. Below, the editor of Script House will introduce to you the solution to PHP reading Chinese garbled mssql json data. Friends who need it can learn together
PHP and web pages use UTF-8 encoding. The database is sql server2008 and uses the default encoding ( 936, which is GBK encoding)
When reading database data, use the json_encode() that comes with PHP to return to the front end, and the result will not be displayed in Chinese.
The solution is as follows:
In this way, the Chinese in sql server 2008 can be displayed normally on the web page.
If you want to insert Chinese into sql server 2008 normally, you also need to add a code: $query = iconv("utf-8", "gbk//ignore", $query);/ /In order to solve the problem of Chinese garbled characters
The complete code is as follows:
$query = iconv("utf-8", "gbk//ignore", $query);//为了解决中文乱码问题 if($result = sqlsrv_query($conn, $query)){ echo true; }else{ echo false; } // echo $query; ?>
Summary: The above is the entire article Content, I hope it will be helpful to everyone’s study.
Related recommendations:
phpMethods and meanings of implementing the singleton pattern
phpMethod to implement image uploading and cutting functions based on CodeIgniter
##phpmetaphone() function andphpDetailed explanation of localeconv() function example
The above is the detailed content of About the solution to Chinese garbled Chinese characters when reading mssql json data with PHP. For more information, please follow other related articles on the PHP Chinese website!