I just got knocked down after our server was upgraded from Debian 4 to 5. We switched to the UTF-8 environment and now we have problems with the correct text printing in the browser, because all the files are in encodings without utf8, such as iso-8859-1, ascii, etc.
I tried many different scripts.
The first one I tried is "iconv". This file does not work, it modifies the contents, but the files in it are still not utf8.
The same problem with enca, encamv, convmv and some other tools that I installed via apt-get.
Then I found python code that uses the Chardet universal detector module to detect the encoding of the file (which works fine), but using the unicode class or the codec class to save it, since utf-8 does not work without any error.
The only way to find the file and its contents converted to UTF-8 is vi.
These are the steps I am doing for a single file:
vi filename.php :set bomb :set fileencoding=utf-8 :wq
Here it is. This works great. But how to do it through a script. I would like to write a script (linux shell) that moves around a directory that takes all the php files and then converts them using vi with the commands above. Since I need to run vi application, I do not know how to do this:
"vi --run-command=':set bomb, :set fileencoding=utf-8' filename.php"
Hope someone can help me.
file encoding vi utf-8 character-encoding
NovumCoder Feb 22 '10 at 15:08 2010-02-22 15:08
source share