PHP – 使用 mb_http_output() 获取或设置 HTTP 输出字符编码

phpserver side programmingprogramming更新于 2025/7/18 20:07:17

PHP 中的 mb_http_output() 函数用于获取或设置 HTTP 输出字符编码。调用此函数后,输出将从设置的内部编码转换为指定的编码。

语法

string|bool mb_http_output(str $encoding = null)

参数

mb_http_output() 仅接受一个参数 −

  • $encoding − 用于将 HTTP 输出字符编码设置为指定的编码。如果省略编码,则 mb_http_output() 将返回当前 HTTP 输出字符编码。

返回值

如果省略编码,则 mb_http_output() 函数将返回当前 HTTP 输出字符编码。否则,成功时返回 True,失败时返回 False。

示例

<?php
   // 它将返回输出字符编码
   $string = mb_http_output();
   var_dump($string);
?>

输出

它将产生以下输出 −

string(5) "UTF-8"

相关文章