Choose a comfortable environment, you can make less to step on a lot of pits, such as the problem of this article, coding problems.
Coding problems mainly exist in three aspects, one. Editor code, two. Network receive (interface) encoding problem, three. Database encoding problem. Here, a problem may be a headache, I would like to summarize the problems and some of the solutions.
Editor question, you are choosing GBK or choose UTF8, this question if put in the project that start now, certainly is choose UTF8, because you do not know, this will let go a lot of code conversion detour. For example, using Json_encode in PHP requires the use of UTF8 format, jquery transmits data with UTF8 ... Of course, the editor encoding is generally designed to match the database code, so if the database has a variety of codes, then the trouble! In particular, if the use of Json_encode, remember to consider transcoding before conversion, in the decoding Json_decode storage database necessary also to turn the code, so that it is not either can not be solved, or the solution is empty, or the solution is garbled.
Network receive (interface) coding problem, this problem is not what we can control, or we negotiate the use of what code, and then do the corresponding transcoding. But if it is to crawl other people's web page information instead of talking about it, then, only guess, guess what code, and then do the corresponding conversion. Example, PHP uses mb_check_encoding to check the encoding, but is based on the given encoding to try, you can rewrite a method to detect the encoding, and then convert.
Database coding problem, should choose how to encode it, or that sentence, no special requirements, hanging UTF8 bar, otherwise, the problem may be where? One-lead data, you may be exported from other databases to the new database, and then garbled, two and the editor does not match, a Chinese is garbled.
In short, the focus is to cooperate, but UTF8 will let you save a lot of power. If there is a coding problem, find the problem from these points!
Development of the coded pits encountered