Home php教程 PHP开发 Solution to the problem of Chinese garbled characters under Linux

Solution to the problem of Chinese garbled characters under Linux

Dec 15, 2016 pm 04:44 PM
linux Chinese garbled code

The files transferred from windows are garbled when copied to linux. We want to display Chinese in linux, what should we do? We first test, can the Chinese in linux be displayed normally? Answer: yes. So the question is relatively simple Obviously, the files copied from Windows cannot be displayed, which means that the formats supported by Windows and Linux are different.
Linux generally uses UTF-8 encoding, but when we edit files on Windows, it uses gb2312 encoding. Therefore, the Chinese encoding will be garbled. To correct this problem is actually very simple. Just convert the file to UTF-8 encoding format and then import it.

Then use the following command to convert:
iconv -f gb2312 -t utf-8 test.txt> testutf8.tzt
(-f is the source encoding, -t converts the target encoding, test.txt source file, testutf8.txt is generated Target encoding file)
Note: Use iconv -l to check the encoding format supported by the system. Of course, you can also add the encoding format:


The default is utf8. If you want to use other encodings such as GBK

Manually change the configuration file command:

shell> vi /etc/sysconfig/i18n

Change LANG= "zh_CN.UTF-8" is modified to:

LANG="zh_CN.GBK"

Save and close, run the following command to make the configuration take effect:

shell> source /etc/sysconfig/i18n

Encode the terminal characters Displayed in Simplified Chinese:

shell> vi /etc/profile.d/chinese.sh

Add the following line: export LC_ALL=zh_CN.GBK

shell> source /etc/profile.d/Chinese.sh


For more articles related to solutions to the problem of Chinese garbled characters under Linux, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1257
29
C# Tutorial
1231
24