首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

mb_output_handler

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

mb_output_handler - 回调函数转换输出缓冲区中的字符编码

描述

代码语言:javascript
复制
string mb_output_handler ( string $contents , int $status )

mb_output_handler()是ob_start()回调函数。mb_output_handler()将输出缓冲区中的字符从内部字符编码转换为HTTP输出字符编码。

参数

contents

输出缓冲区的内容。

status

输出缓冲区的状态。

返回值

转换后的字符串。

更新日志

版本

描述

4.1.0

当满足以下条件时,此处理程序现在添加字符集HTTP标头:尚未使用header()设置Content-Type。默认的MIME类型以text /开头。mbstring.http_input设置不是pass。

  • Content-Type尚未使用header()进行设置。
  • 默认的MIME类型以text /开头。

例子

示例#1 mb_output_handler()示例

代码语言:javascript
复制
<?php
mb_http_output("UTF-8");
ob_start("mb_output_handler");
?>

注意

注意:如果要输出二进制数据,例如图像,必须在将任何二进制数据发送到客户端之前使用header()设置Content-Type:头(例如,header(“Content-Type:image / png” ))。如果发送Content-Type:标题,则不会执行输出字符编码转换。请注意,如果发送了“Content-Type:text / *”,则内容主体将被视为文本; 转换将发生。

另请参阅

  • ob_start() - 打开输出缓冲

← mb_list_encodings

mb_parse_str →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com