0

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.

2
  • Which version of VIM are you using? Can your terminal show the ä character? Commented Nov 25, 2009 at 14:21
  • what is your locale? (output of locale in terminal?) it might helph if you switch your whole system to a UTF-8 locale. Although that will give you a mess with all non-UTF-8 filenames :-( Commented Nov 28, 2009 at 14:48

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

I tried: gvim ++enc=utf-8 test.me "-bash: gvim: command not found" so I then tried: vim ++enc=utf-8 test.me "test.me" 1L, 23C Error detected while processing command line: E492: Not an editor command: +enc=utf-8 What am i mising?
I suspect that your Vim is not compiled with multi-byte support. What does :echo has('multi_byte') say? If it's not '1', then you've almost certainly not got a unicode enabled vim, so you'll need to either install another one or compile it yourself. Neither of these is difficult: which OS?
:echo has('multi_byte'). It does output 1
Oops, my bad: I was abusing ++enc. Try the edited instructions above.
Still no luck! I really hate encoding/fileencoding!
1
  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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.