Home > php教程 > PHP开发 > body text

Solution to the problem of Chinese garbled characters under Linux

高洛峰
Release: 2016-12-15 16:44:36
Original
1396 people have browsed it

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!

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!