linux a quick solution to system coding problems

  • 2020-05-12 06:41:19
  • OfStack

1 time in 1 lately run dry in linux system under the code of the application of problem, after the final check is found to be customer linux system default code set is not correct, this causes the code 1, Chinese characters were written application is dead can show normal, but from the database or to take out from the program read the Chinese characters will appear garbled.

The following is an introduction to the solution to the problem of applying garbled code in the report due to the incorrect encoding setting of linux system.

Step 1: check the system encoding for linux.

Check the system code of linux to see if the system supports Chinese. Enter the command locale in the terminal of the linux system and you will see the printed system code information. If the printed information is as follows, the system code does not support Chinese:

LANG=en_US.UTF-8

LC_CTYPE = "en_US. UTF - 8"

LC_NUMERIC = "en_US. UTF - 8"

LC_TIME = "en_US. UTF - 8"

LC_COLLATE = "en_US. UTF - 8"

LC_MONETARY = "en_US. UTF - 8"

LC_MESSAGES = "en_US. UTF - 8"

LC_PAPER = "en_US. UTF - 8"

LC_NAME = "en_US. UTF - 8"

LC_ADDRESS = "en_US. UTF - 8"

LC_TELEPHONE = "en_US. UTF - 8"

LC_MEASUREMENT = "en_US. UTF - 8"

LC_IDENTIFICATION = "en_US. UTF - 8"

Step 2: modify the system default encoding Settings

If it is found that the system code does not support Chinese, then the system code must be modified to support Chinese, so that the rungan report of Chinese in the application will not be scrambled.

The method to modify the system code is as follows:

/etc/sysconfig/i18n

Controls the system font settings. The language variables are used in /etc/profile.d/lang.sh. An example i18n file:

LANG = "en_US. GB18030"

LANGUAGE= "en_US. GB18030: en_US. GB2312: en_US"

SUPPORTED = "en_US. GB18030: en_US: en: en_US. UTF - 8: en_US: en"

SYSFONT lat0 - sun16 = ""

The above is that the system's default character set is in English. If you want to set the character set to support Chinese, you can change the system's default character set by setting this file.

In addition, the path variable declaration can be added to the user's environment variable or the user's environment variable file:

Declared in the preprocessing file of the system, so as to affect the whole system:

#vi /etc/profile

Add at the end of the file

LC_ALL = "zh_CN. GBK"

export LANG = "zh_CN. GBK"

Declared in the user's preprocessing file, which works for individual users:

#vi /root/.bash_profile

Add at the end of the file

export LC_ALL = "zh_CN. GBK"

export LANG = "zh_CN. GBK"

The above configuration restarts the server for the changes to take effect.

Step 3: view the modified system default encoding.

Go through the above steps and restart the computer, then enter the command locale in the terminal, and you will see the character set information of the system change

So the system code support Chinese, after the above modification, because the system default code does not support Chinese caused by the messy code can be solved smoothly.


Related articles: