Iconv

iconv[1]是一个计算机程序[2]以及一套应用程序编程接口[3]的名称。它的作用是在多种国际编码格式之间进行文本内码的转换。支持的内码包括:

  • Unicode相关编码,如UTF-8、UTF-16等等
  • 各国采用的ANSI编码,其中包括GB2312、BIG5等中文编码方式。

作为应用程序的iconv采用命令行界面,允许将某种特定编码的文件转换为另一种编码。

用法

文件infile从GB18030编码转换至UTF-8编码并写入到文件outfile中:

iconv -f GB18030 -t utf-8 < infile > outfile

PHP(页面存档备份,存于互联网档案馆)语言对iconv封装了3个函数:

  • iconv_open函数用于初始化用于转换的内部缓冲区,需要指明需要从何种编码方式转换到哪一种。
  • iconv函数进行实际的转换,需要给出两个间接缓冲区指针和剩余字节数指针。该函数需要更新所有相关信息,因此将不可改写的指针传递给iconv是错误的。
  • iconv_close函数释放iconv_open函数的缓冲区。

iconv基于GPL公开源代码,是GNU项目的一部分。在各种UNIX操作系统下均可使用,而在Windows系统,需要特殊的环境如cygwin或者GnuWin32等软件平台下方可使用。现在在SourceForge上也有运行于Windows系统的,需要同时安装gettext程序。

目前,libiconv已经包含在C运行时刻库libc.so中。因此,Linux平台上使用iconv库函数的程序,需要包含<iconv.h>,但链接时不需要引入libiconv库了。

参考文献

  1. ^ R: Convert Character Vector between Encodings. astrostatistics.psu.edu. [21 April 2018]. (原始内容存档于2020-10-31). 
  2. ^ iconv. pubs.opengroup.org. [21 April 2018]. (原始内容存档于2020-10-28). 
  3. ^ iconv. www.opengroup.org. [21 April 2018]. (原始内容存档于2010-12-08). 

外部链接

文件系統
  • cat
  • cd
  • chmod
  • chown
  • chgrp
  • cksum
  • cmp
  • cp
  • dd
  • du
  • df
  • file
  • fsck
  • fuser
  • ln
  • ls
  • mkdir
  • mount
  • mv
  • pax英语pax (Unix)
  • pwd
  • rm
  • rmdir
  • size
  • split
  • stat
  • tee
  • touch
  • type英语type (Unix)
  • umask英语umask
程序
  • at
  • bg
  • chroot
  • cron
  • fg
  • kill
  • killall英语killall
  • nice
  • pgrep
  • pkill英语pkill
  • ps
  • pstree英语pstree
  • time
  • top
用户环境
  • clear
  • env
  • exit
  • history英语history (Unix)
  • id
  • logname
  • mesg英语mesg
  • passwd
  • su
  • sudo
  • uptime
  • talk英语talk (software)
  • tput英语tput
  • uname
  • w
  • wall英语wall (Unix)
  • who
  • whoami
  • write英语write (Unix)
文本编辑
  • awk
  • banner英语banner (Unix)
  • basename
  • comm英语comm
  • csplit英语csplit
  • cut
  • diff
  • dirname
  • ed
  • ex
  • fmt英语fmt
  • fold英语fold (Unix)
  • head英语head (Unix)
  • iconv
  • join英语join (Unix)
  • less
  • more
  • nl英语nl (Unix)
  • paste英语paste (Unix)
  • sed
  • sort英语sort (Unix)
  • spell英语spell (Unix)
  • strings英语strings (Unix)
  • tail
  • tr
  • uniq英语uniq
  • vi
  • wc
  • xargs
壳层内建
网络
查找
文档
  • apropos英语apropos (Unix)
  • help英语help (command)
  • man
软件开发
杂项
  • bc
  • cal
  • dc
  • expr
  • lp英语lp (Unix)
  • lpr
  • sleep
  • true和false
  • yes