Windows USES Gvim to write PHP to generate Chinese garble code problem solution

  • 2020-05-05 10:59:57
  • OfStack

First of all: to find out the cause of garbled code. I always thought it was because of the browser. As a result, I found some scrambled codes in chrome, firefox and IE9, so the browser factor can be excluded. To verify my guess, Gvim,
I simply wrote an php file
using notepad (note)
 
<?php 
echo " hello "; 
echo " The world "; 
?> 

The result was no garbled code, so the problem was Gvim, and the result followed.
So I started looking at the Gvim configuration file (_vimrc), and now I'm going to show you the configuration before I created the garbled code:
 
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 =~ '\<cmd' 
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 . ' > ' . arg3 . eq 
endfunction 
" Set the default background color  
colors desert 
" Set not to backup automatically  
set nobackup 
" Set the default font and size  
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 

Here's what enconding,fileeconding,fileecondings mean in the configuration file:
encoding: the character encoding used internally in GVim, including buffer (buffer), menu text, message text, and so on in Vim.
The user's manual recommends changing its value only in.vimrc, and in fact it seems to make sense only to change its value in.vimrc.
fileencoding: the character encoding of the currently edited file in GVim. Vim saves the file in this character encoding as well (whether the file is new or not).
fileencodings: GVim starts by probing the character encoding of the file to be opened one by one in the character encoding it lists, and sets fileencoding to the final detected character encoding.
So it's best to put Unicode at the top of the list and latin1 at the bottom of the list.
Where: chinese is cp963 code
It suddenly occurred to me that the default character set in my browser is GBK, and the setting code in _vimrc is utf-8, which does not correspond to
 
colors desert 
set nobackup 
set guifont=Courier_New:h12:cANSI 
" Handles the display of garbled text  
set encoding=utf-8 
set fileencodings=chinese 
set fileencoding=chinese 
" Handle menu and right - click menu garbled code  
source $VIMRUNTIME/delmenu.vim 
source $VIMRUNTIME/menu.vim 
" To deal with consle Output the code  
language messages zh_CN.utf-8 
syntax enable 
syntax on 

After the modification is completed, restart Gvim and the Chinese garbled code problem is solved.

Related articles: