ob_iconv_handler

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

ob_iconv_handler以输出缓冲处理程序转换字符编码

说明

string ob_iconv_handler ( string $contents , int $status )

将字符编码从 internal_encoding 转换到 output_encoding

internal_encodingoutput_encoding 应当在 php.ini 文件或 iconv_set_encoding() 中定义。

参数

关于处理程序参数的信息,参见 ob_start()

返回值

关于处理程序返回值的信息,参见 ob_start()

范例

Example #1 ob_iconv_handler() 例子:

<?php
iconv_set_encoding
("internal_encoding""UTF-8");
iconv_set_encoding("output_encoding""ISO-8859-1");
ob_start("ob_iconv_handler"); // 开始输出缓冲
?>

参见

add a note add a note

User Contributed Notes 1 note

up
0
st33mann at gmx dot n3t
12 years ago
Just a quick note that may be helpful for some:
It seems to me that this function also modifies the HTTP Content-Type header that's sent to the client (at least in combination with the iconv_set_encoding() function).

If you specify an encoding ending with "//TRANSLIT" or "//IGNORE" (valid in iconv), it will still send the encoding name in the HTTP header. This makes it an invalid character set unfortunately.

For example:
<?php
iconv_set_encoding
("internal_encoding","UTF-8");
iconv_set_encoding("output_encoding","ISO-8859-1//TRANSLIT");
ob_start("ob_iconv_handler");
?>
will send a Content-Type header of "ISO-8859-1//TRANSLIT".
To Top