iconv -l
在 CentOS 6.5 上输出的编码太少:
$ iconv -l
10646-1:1993, 10646-1:1993/UCS4, ANSI_X3.4-1968, ANSI_X3.4-1986, ANSI_X3.4, ASCII, CP367, CSASCII, CSUCS4, IBM367,
ISO-10646, ISO-10646/UCS2, ISO-10646/UCS4, ISO-10646/UTF-8,
ISO-10646/UTF8, ISO-IR-6, ISO-IR-193, ISO646-US, ISO_646.IRV:1991,
OSF00010020, OSF00010100, OSF00010101, OSF00010102, OSF00010104,
OSF00010105, OSF00010106, OSF05010001, UCS-2, UCS-2BE, UCS-2LE,
UCS-4, UCS-4BE, UCS-4LE, UCS2, UCS4, UNICODEBIG, UNICODELITTLE,
US-ASCII, US, UTF-8, UTF8, WCHAR_T
但在我的 Ubuntu 上,这个列表似乎更长,这里有所不同:
CentOS6.5:
$ php -a
php > echo iconv('utf8', 'gbk', 'abc');
PHP Notice: iconv(): Wrong charset, conversion from `utf8' to `gbk' is not allowed in php shell code on line 1
php > quit
$ php -i|grep iconv
iconv
iconv support => enabled
iconv implementation => glibc
iconv library version => 2.12
iconv.input_encoding => ISO-8859-1 => ISO-8859-1
iconv.internal_encoding => ISO-8859-1 => ISO-8859-1
iconv.output_encoding => ISO-8859-1 => ISO-8859-1
Ubuntu 14.04:
$ php -a Interactive mode enabled
php > echo iconv('utf8', 'gbk', "abc\n");
abc
php > quit
$ php -i|grep iconv
iconv
iconv support => enabled
iconv implementation => glibc
iconv library version => 2.19
iconv.input_encoding => ISO-8859-1 => ISO-8859-1
iconv.internal_encoding => ISO-8859-1 => ISO-8859-1
iconv.output_encoding => ISO-8859-1 => ISO-8859-1
但是我不想重新编译 glibc(这将是一项艰巨的工作),关于如何添加新的编码支持有什么想法吗?
答案1
之后yum upgrade
,在安装 glibc-2.12-1.132.el6_5.2.x86_64 时,iconv 可以正常工作,而旧的软件包是 glibc-2.12-1.132.el6.x86_64。