iconv_set_encoding

(PHP 4 >= 4.0.5, PHP 5, PHP 7)

iconv_set_encoding为字符编码转换设定当前设置

说明

iconv_set_encoding ( string $type , string $charset ) : bool

type 设置的值从内部配置变量更改为 charset

参数

type

type 的值可以是以下其中任意一个:

  • input_encoding
  • output_encoding
  • internal_encoding

charset

字符集。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #1 iconv_set_encoding() 例子

<?php
iconv_set_encoding
("internal_encoding""UTF-8");
iconv_set_encoding("output_encoding""ISO-8859-1");
?>

参见

User Contributed Notes

Coralie B 15-Sep-2016 09:10
I encountered the same issue than joe dot bowman at edigitalresearch.com

Even if i read on the web that it is a usual issue when using PHP 5.6 and upper, i didn't encounter it on every sites on which i use PHP 5.6.

Nevertheless, i had to find a solution because, when the issue appears, it's embarrassing. This is what i found thanks to Alexandra López on http://hasibul.info.

Instead of :
if (function_exists('iconv'))
{
// These are settings that can be set inside code
    iconv_set_encoding("internal_encoding", "UTF-8?);
    iconv_set_encoding("input_encoding", "UTF-8?);
    iconv_set_encoding("output_encoding", "UTF-8?);
}

i use :
if (PHP_VERSION_ID < 50600) {
    iconv_set_encoding('input_encoding', 'UTF-8');
    iconv_set_encoding('output_encoding', 'UTF-8');
    iconv_set_encoding('internal_encoding', 'UTF-8');
} else {
    ini_set('default_charset', 'UTF-8');
}
joe dot bowman at edigitalresearch.com 18-Nov-2014 10:26
As of PHP 5.6, this throws a Deprecated level error, as is consistent with setting the iconv.*_encoding ini settings:

iconv_set_encoding('internal_encoding', 'UTF-8');

triggers:

PHP Deprecated:  iconv_set_encoding(): Use of iconv.internal_encoding is deprecated in ...
pasamio at gmail dot com 03-Jan-2008 11:18
On PHP 5.2.5 when iconv.*_encoding values are set using php_admin_value in the Apache configuration file, this call will fail and return false.