Garbled data queried by php often occurs when operating the database, so this article will introduce its solution.
First of all, set the encoding method of MySQL to utf8,
Secondly, the encoding of writing to the database and the encoding of reading the database must also be unified to utf8
mysqli_query($conn,"set character set 'utf8'"); mysqli_query($conn,"set names 'utf8'");
Finally Just set the head and write it at the top of the document.
header('content-type:text/json;charset=utf-8');
If you encounter the problem of converting the queried data to json, use JSON_encode($data);
You will find that Chinese is actually installed as Unicode. Fortunately, a configuration appeared after 5.4. JSON_UNESCAPED_UNICODE
Case
$json = JSON_encode($resoult_all,JSON_UNESCAPED_UNICODE);
Try outputting again and it should be fine.
This article introduces the solution to the problem of garbled data queried by PHP. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
Explain the related operations of orderly splitting of PHP strings
How to use PHP to calculate The distance between two longitudes and latitudes
Explain related examples of PHP array traversal
The above is the detailed content of How to solve the problem of garbled data queried by php. For more information, please follow other related articles on the PHP Chinese website!