Recently, there is a php project, garbled characters are a headache problem
Solution:
1. Add header("Content-Type: text/html; charset=utf-8");
2. Add mysql_query("set names 'encoding'"); before the PHP program that needs to perform database operations. The encoding is consistent with the PHP encoding. If the PHP encoding is gb2312, then the mysql encoding is gb2312. If it is utf-8, then
MySQL encoding is utf8, so that there will be no garbled characters when inserting or retrieving data
mysql_query("set names 'utf8'") or mysqli_query("set names 'utf8'");
It should be noted that the areas marked in red are utf8, not utf-8;
3. The encoding of the html file used must also be consistent, generally using utf-8;
in the php file