Php garbled characters are saved to the mysql database ,. Php saved to mysql database in Chinese garbled code, recent php project, garbled code is a headache solution: 1, php file add header (Content-Type: texthtml; charsetutf-8) chinese garbled characters saved by php to the mysql database,
Garbled code is a headache for php projects recently.
Solution:
1. add the header to the php file ("Content-Type: text/html; charset = utf-8 ");
2. add mysql_query ("set names 'Encoding '") before the php program that requires database operations. the encoding is the same as that of php. If php encoding is gb2312, mysql encoding is gb2312, for UTF-8
Mysql code is utf8, so no garbled characters will appear during data insertion or retrieval.
Mysql_query ("set names 'utf8'") or mysqli_query ("set names 'utf8 '");
Note that utf8 is not UTF-8 in red;
3. the encoding of the html file used must be the same. UTF-8 is generally used;
Http://www.bkjia.com/PHPjc/1128382.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1128382.htmlTechArticlephp saved to mysql database in Chinese garbled, recent php project, garbled is a headache problem solution: 1, php file add header (Content-Type: text/html; charset = utf-8 ")...