What encoding methods do you need to pay attention? There have been a lot of coding-related things involved in such a long web design. But today I encountered another garbled code, so I had to search for it and solve it.
Here are the encoding methods I know:
1.
(Notify the browser of the decoding method on this page)
2.
Encoding method for saving a document
3.
Database encoding method (set when defining a database or table)
4.
SQL statement encoding method (SET by "SET NAMES UTF8)
What is the final encoding method? In this case:
A static page transfers data from a text data box to another php page through the get method. This php page places the data in an insert statement and runs this SQL statement.
What is the encoding method of this query statement? Is it static page encoding, dynamic page encoding, or something else? Anyway, I set all to UTF-8, successfully inserted, no garbled. However, the problem is that the "set names UTF8" setting is required for each insert. how can we SET UTF8 to the default encoding method of SQL statements?
What else do we need to pay attention to the encoding method?
Reply to discussion (solution)
All "encoding methods" are based on the output page.
Mysql has the adaptive "encoding" function (it is not clear to other databases), that is, if you ask him to return the encoding, he will return the encoding.
The principle is: coding is required for almost every IO.
Loading php is one time, because the system/web server and php are two encodings.
Php output. the client system/browser and output characters are two encodings.
Read/write files, read/write databases, include ...... And so on.
I would like to mention a few more easily overlooked
Cookies. this is unlikely, but you should pay attention to it.
Session. I didn't test how to use a session together with two php codes. try again.
Sending and receiving, such as curl, socket, and API
Interaction with other languages
......