If the Chinese text is submitted using a form, there will be no garbled characters, and there will be garbled characters when submitted using ajax. Why?
I understand that when I write the source code, I usually write it in Notepad. By default, I use ANSI encoding to save it, "<meta http-equiv = Content-Type content = text/html; charset = UTF-8>" or "header ('content-Type: text/html; charset = UTF-8 '); "specifies the webpage encoding, so when displayed in a browser, its encoding is identified as" GB2312 ". When the current station transmits data to the background, if the form is submitted, the frontend and backend will communicate with each other in GB2312 encoding without garbled characters. If ajax is used to submit data, ajax in the front-end to send data encoding from "GB2312" into "UTF-8" and then to the background, then the received back-end data as a "UTF-8" and convert it to "GB2312" after displayed on the front-end page, so garbled.
So to solve the garbled code, to data encoding conversion in the background, the data received in the background using PHP mb_convert_encoding ("to convert the data", "gb2312", "UTF-8 ") after conversion, the data is stored in the database. While the background returned to the foreground of the Chinese data also use mb_convert_encoding ("to return the data", "UTF-8", "gb2312") Conversion back.