回复:UTF-8、PHP 和 XML Mysql

发布于 2024-08-12 01:03:53 字数 672 浏览 6 评论 0原文

这与 UTF-8、PHP 和 XML Mysql 有关,我是仍在努力让我的头脑清醒。

我有几个单独的问题,希望能帮助我了解如何解决我遇到的问题。

我正在尝试从数据库读取值并输出到 UTF-8 格式的文件中。但我遇到了编码问题,所以我想我应该删除所有代码并开始:

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

但在 vim 中,我什至无法输入该字符串,每次粘贴它时我都会得到 Otivägen

我尝试创建一个仅包含该字符串的空白 PHP 文件并将其上传,但是当我再次 cat 该文件时,我得到了 Otivägen

我的问题是......

  1. 为什么 vim 显示它像 这?
  2. 如果文件被下载了 如果应用程序正确显示 期待 UTF-8 吗?
  3. 我怎样才能把这个字符串输出到 最终将是 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 ...

  1. Why is vim displaying it like
    this?
  2. If the file is downloaded would it
    display correctly if an application
    was expecting UTF-8?
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只是一片海 2024-08-19 01:03:53

Vim 中的编码存在很多混乱。有两种编码设置:'encoding''fileencoding'

'encoding' 是与当前 vim 会话相关的一个 - 我一直将其保留为 'utf-8',但随后我只使用 gVim 或支持 unicode 的终端。

'fileencoding' 是文件本身的编码,它是自动检测的,或者可以用设置(++enc)或我认为的模型行覆盖。它是根据 'fileencodings' 选项检测的。

试试这个:

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

有关更多信息,请参阅:

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

另请参阅 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:

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

童话 2024-08-19 01:03:53
  1. Vim 从 6.0 版开始支持 UTF-8。默认情况下,您的系统可能不使用 UTF-8 - 您可能会看到以 ASCII(或其他 8 位固定编码)显示的 UTF-8 文本。

  2. 应该的。当您提供文件时,将文件的编码设置为 UTF-8。

  3. 任何文件写入函数都会接受这一点 - UTF-8 只是一个字节序列。

  1. 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).

  2. It should. Set the encoding on the file to UTF-8 when you serve it.

  3. Any file writing function would accept this - UTF-8 is just a sequence of bytes.

遗忘曾经 2024-08-19 01:03:53

这可能不是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文