Using Gvim to write PHP in Windows to generate Chinese garbled characters _ PHP Tutorial

Source: Internet
Author: User
In Windows, Gvim is used to write PHP to generate Chinese garbled characters. First, find out the cause of garbled text. I always thought it was the reason for the browser. as a result, I found garbled characters in chrome, firefox, and IE9, so the browser can be ruled out. To verify, first, find out the cause of garbled text. I always thought it was the reason for the browser. as a result, I found garbled characters in chrome, firefox, and IE9, so the browser can be ruled out. To verify that I guess the reason is Gvim,
I used notepad (note) to write a php file.

The code is as follows:


Echo "Hello ";
Echo "world ";
?>


The result is not garbled, so the problem lies in Gvim. This conclusion is justified.
So I started to study the Gvim configuration file (_ vimrc). now let's take a look at the configuration before I generated the garbled code (note: I modified it before ):

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.'> '. arg3. eq
Endfunction
"Set the default background color
Colors desert
"Disable automatic backup
Set nobackup
"Set default font and size
Set guifont = Courier_New: h12: cANSI
Set termencoding = gbk
Set encoding = UTF-8
"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


Description: enconding, fileeconding, and fileecondings in the configuration file:
Encoding: the character encoding method used inside GVim, including Vim buffer, menu text, and message text.
In the user manual, it is recommended to change its value only in. vimrc. In fact, it seems only meaningful to change its value in. vimrc.
Fileencoding: the character encoding method of the file currently edited in GVim. when saving the file, Vim also saves the file as this encoding method (whether new or not ).
Fileencodings: when GVim is started, it detects the character encoding methods of the files to be opened one by one based on the character encoding methods listed in it, and sets fileencoding as the final character encoding method.
Therefore, it is best to put the Unicode encoding method at the beginning of this list, and put latin1 in the latin1.
Where: chinese is cp963 encoding
Here I suddenly remembered that the default character set in my browser is GBK, while the encoding set in _ vimrc is UTF-8, which does not correspond to each other,

The code is as follows:


Colors desert
Set nobackup
Set guifont = Courier_New: h12: cANSI
"Garbled characters are displayed in the processed text.
Set encoding = UTF-8
Set fileencodings = chinese
Set fileencoding = chinese
"Process menu and context menu garbled characters
Source $ VIMRUNTIME/delmenu. vim
Source $ VIMRUNTIME/menu. vim
"Handling consystemic output garbled characters
Language messages zh_CN.utf-8
Syntax enable
Syntax on


After the modification, restart Gvim to solve the Chinese garbled problem.

Bytes. I always thought it was the reason for the browser. as a result, I found garbled characters in chrome, firefox, and IE9, so the browser can be ruled out. To verify...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.