回复:UTF-8、PHP 和 XML Mysql
这与 UTF-8、PHP 和 XML Mysql 有关,我是仍在努力让我的头脑清醒。
我有几个单独的问题,希望能帮助我了解如何解决我遇到的问题。
我正在尝试从数据库读取值并输出到 UTF-8 格式的文件中。但我遇到了编码问题,所以我想我应该删除所有代码并开始:
$string = "Otivägen";
// then output to a file.
但在 vim
中,我什至无法输入该字符串,每次粘贴它时我都会得到 Otivägen
我尝试创建一个仅包含该字符串的空白 PHP 文件并将其上传,但是当我再次 cat
该文件时,我得到了 Otivägen
。
我的问题是......
- 为什么
vim
显示它像 这? - 如果文件被下载了 如果应用程序正确显示 期待 UTF-8 吗?
- 我怎样才能把这个字符串输出到 最终将是 XML 的文件 UTF-8 编码的文件。
目前我对编码的理解有限,我正在尝试理解它。
This is relating to UTF-8, PHP and XML Mysql, which I am still trying to get my head around.
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. 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
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
.
My questions are ...
- Why is
vim
displaying it like
this? - If the file is downloaded would it
display correctly if an application
was expecting UTF-8? - How can I output this string into a
file that will eventually be an XML
file in UTF-8 encoding.
My understanding of encoding is limited at the moment, and I am trying to understand it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Vim 中的编码存在很多混乱。有两种编码设置:
'encoding'
和'fileencoding'
。'encoding'
是与当前 vim 会话相关的一个 - 我一直将其保留为 'utf-8',但随后我只使用 gVim 或支持 unicode 的终端。'fileencoding'
是文件本身的编码,它是自动检测的,或者可以用设置(++enc
)或我认为的模型行覆盖。它是根据'fileencodings'
选项检测的。试试这个:
有关更多信息,请参阅:
另请参阅 http://vim.wikia.com/wiki /类别:编码
There is a lot of confusion associated with encodings in Vim. There are two encoding settings,
'encoding'
and'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.'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. It is detected based on the'fileencodings'
option.Try this:
For more information, see:
See also http://vim.wikia.com/wiki/Category:Encoding
Vim 从 6.0 版开始支持 UTF-8。默认情况下,您的系统可能不使用 UTF-8 - 您可能会看到以 ASCII(或其他 8 位固定编码)显示的 UTF-8 文本。
应该的。当您提供文件时,将文件的编码设置为 UTF-8。
任何文件写入函数都会接受这一点 - UTF-8 只是一个字节序列。
Vim supports UTF-8 from version 6.0. 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).
It should. Set the encoding on the file to UTF-8 when you serve it.
Any file writing function would accept this - UTF-8 is just a sequence of bytes.
这可能不是 vim 问题 - 如果您的终端软件未设置为 utf-8 那么无论 vim 在做什么,您都会看到上述问题。
This might not be a vim issue - if your terminal software is not set to utf-8 then you'll see the above issues regardless of what vim is doing.