Home > Backend Development > PHP Tutorial > How to solve the problem of Chinese garbled characters when writing PHP using Gvim under Windows_PHP Tutorial

How to solve the problem of Chinese garbled characters when writing PHP using Gvim under Windows_PHP Tutorial

WBOY
Release: 2016-07-21 15:31:00
Original
973 people have browsed it

First: find out the cause of the garbled code. I always thought it was due to the browser, but garbled characters appeared in Chrome, Firefox, and IE9, so the browser factor can be ruled out. In order to verify the reason I guessed it was Gvim,
I simply wrote a php file using Notepad (note)

Copy the code The code is as follows:

echo "Hello";
echo "World";
?>

The result is not garbled, so the problem Just because of Gvim, this conclusion comes naturally.
So, I started to study Gvim’s configuration file (_vimrc). Now I will show you the configuration before the garbled code was generated (Note: I have modified it before):
Copy code The code is as follows:

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set diffexpr= MyDiff()
function MyDiff()
let opt ​​= '-a --binary '
if &diffopt =~ 'icase' | let opt ​​= opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt ​​= opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ 'let cmd = '""' . $VIMRUNTIME . 'diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . ' diff"'
endif
else
let cmd = $VIMRUNTIME . 'diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > set guifont=Courier_New:h12:cANSI
set termencoding=gbk
set encoding=utf-8
"The cause of the problem
set fileencoding=chinese
set fileencodings=ucs-bom,utf -8,chinese
set langmenu=zh_CN.utf-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
language messages zh_cn.utf-8
language messages zh_cn.utf-8
syntax enable
syntax on


Something needs to be explained here: the meaning of encoding, fileeconding, fileecondings in the configuration file:
encoding: characters used internally by GVim Encoding method, including Vim's buffer, menu text, message text, etc.
The user manual recommends changing its value only in .vimrc. In fact, it seems that it only makes sense to change its value in .vimrc.
fileencoding: The character encoding of the file currently edited in GVim. When Vim saves the file, it will also be saved in this character encoding (regardless of whether it is a new file or not).
fileencodings: When GVim starts, it will detect the character encoding of the file to be opened one by one according to the character encoding it lists, and set fileencoding to the final detected character encoding.
So it is best to put the Unicode encoding at the top of this list and the Latin encoding latin1 at the end.
Among them: chinese is the cp963 encoding
At this point, I suddenly remembered that the default character set in my browser is GBK, and the set encoding in _vimrc is utf-8. The two do not correspond.



Copy code

The code is as follows:

colors desert set nobackup set guifont=Courier_New:h12:cANSI "Processing garbled characters in textset encoding=utf-8
set fileencodings=chinese
set fileencoding=chinese
"Processing garbled characters in menus and right-click menus
source $VIMRUNTIME/delmenu .vim
source $VIMRUNTIME/menu.vim
"Processing console output garbled characters
language messages zh_CN.utf-8
syntax enable
syntax on


Modify After completion, restart Gvim and the Chinese garbled problem is solved.



http://www.bkjia.com/PHPjc/323110.html
www.bkjia.com
true

http: //www.bkjia.com/PHPjc/323110.htmlTechArticleFirst: find out the cause of the garbled code. I always thought it was due to the browser, but as a result, garbled characters appeared in Chrome, Firefox, and IE9, so the browser factor can be ruled out. In order to verify...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template