Solution to Chinese garbled Chinese characters when reading mssql json data with PHP

高洛峰
Release: 2023-03-04 11:24:02
Original
1356 people have browsed it

PHP and web pages use UTF-8 encoding, and the database is sql server2008, using the default encoding (936, which is GBK encoding)

When reading database data, use PHP’s own json_encode( ) returns to the front end, the results are not 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 Chinese garbled problem

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; ?>
Copy after login

The above is the solution introduced by the editor to read Chinese garbled mssql json data with PHP. I hope it will be helpful to you. Everyone helps!

For more related articles on solutions to Chinese garbled Chinese characters when reading mssql json data with PHP, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!