简体   繁体   English

回复:UTF-8,PHP和XML Mysql

[英]re: UTF-8, PHP and XML Mysql

This is relating to UTF-8, PHP and XML Mysql , which I am still trying to get my head around. 这与UTF-8,PHP和XML Mysql有关 ,但我仍在设法解决。

I Have a couple of separate questions that will hopefully help me understand how to resolve the issues I am having. 我有几个单独的问题,希望可以帮助我理解如何解决我遇到的问题。

I am trying to read values from a database and output into a file in UTF-8 format. 我正在尝试从数据库读取值并将其输出为UTF-8格式的文件。 But I am having encoding issues, so i thought I would strip back all my code ans start with: 但是我遇到了编码问题,所以我想我应该把所有的代码都从下面开始:

$string = "Otivägen";
// then output to a file.

But in vim i cant even enter the that string, every time I paste it in I get Otivägen 但是在vim我什至无法输入该字符串,每次将其粘贴到Otivägen

I tried to create a blank PHP file with only that string and upload it, but when I cat the file again I get Otivägen . 我试图创建一个空的PHP文件只用该字符串并上传,但是当我cat文件再次,我得到Otivägen

My questions are ... 我的问题是...

  1. Why is vim displaying it like this? 为什么vim显示它?
  2. If the file is downloaded would it display correctly if an application was expecting UTF-8? 如果下载了文件,如果应用程序期望使用UTF-8,是否可以正确显示?
  3. How can I output this string into a file that will eventually be an XML file in UTF-8 encoding. 如何将这个字符串输出到最终将成为UTF-8编码的XML文件的文件中。

My understanding of encoding is limited at the moment, and I am trying to understand it. 目前,我对编码的理解还很有限,我正在尝试理解它。

There is a lot of confusion associated with encodings in Vim. Vim中的编码有很多困惑。 There are two encoding settings, 'encoding' and 'fileencoding' . 有两种编码设置, 'encoding''fileencoding'

'encoding' is the one that relates to the current vim session - I leave this as 'utf-8' all the time, but then I only use gVim or unicode-enabled terminals. 'encoding'是与当前vim会话相关'encoding' -我一直将其保留为“ utf-8”,但是后来我仅使用gVim或启用了unicode的终端。

'fileencoding' is the encoding of the file itself, which is automatically detected or can be overridden with a setting ( ++enc ) or a modeline I believe. 'fileencoding'是文件本身的编码,它会自动检测到,或者可以用设置( ++enc )或我相信的modeline覆盖。 It is detected based on the 'fileencodings' option. 根据'fileencodings'选项检测到它。

Try this: 尝试这个:

vim
:set encoding=utf-8
:e ++enc=utf-8 test_file.php
i
$string = "Otiv<Ctrl-K>a:gen";
:w

For more information, see: 有关更多信息,请参见:

:help 'encoding'
:help 'fileencoding'
:help 'fileencodings'
:help ++enc
:help modeline

See also http://vim.wikia.com/wiki/Category:Encoding 另请参见http://vim.wikia.com/wiki/Category:Encoding

  1. Vim supports UTF-8 from version 6.0 . Vim 从版本6.0开始支持UTF-8。 Your system is likely not using UTF-8 by default - you're likely seeing UTF-8 text displayed in ASCII (or another 8-bit fixed encoding). 默认情况下,您的系统可能未使用UTF-8-您可能会看到以ASCII(或其他8位固定编码)显示的UTF-8文本。

  2. It should. 这应该。 Set the encoding on the file to UTF-8 when you serve it. 提供文件时,将文件的编码设置为UTF-8。

  3. Any file writing function would accept this - UTF-8 is just a sequence of bytes. 任何文件写入功能都可以接受-UTF-8只是字节序列。

这可能不是vim问题-如果您的终端软件未设置为utf-8,则无论vim在做什么,您都会看到上述问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM