Current Location: Home> Function Categories> mb_http_output

mb_http_output

Set/get HTTP output character encoding
Name:mb_http_output
Category:Multi-byte string
Programming Language:php
One-line Description:Set HTTP output character encoding

Function name: mb_http_output()

Function description: mb_http_output() function sets the HTTP output character encoding.

Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7

Syntax: mb_http_output([string $encoding = mb_http_output()])

parameter:

  • encoding (optional): The character encoding to set. By default, this parameter is empty, indicating that the current HTTP output character encoding is obtained.

Return value: If no encoding parameter is provided, the current HTTP output character encoding is returned. If encoding parameter is provided, return true to indicate the setting is successful, or false to indicate the setting is failed.

Example:

  1. Get the current HTTP output character encoding:
 $encoding = mb_http_output(); echo "当前的HTTP 输出字符编码为:" . $encoding;

Output:

当前的HTTP 输出字符编码为:UTF-8
  1. Set the HTTP output character encoding to GBK:
 $result = mb_http_output('GBK'); if($result) { echo "HTTP 输出字符编码设置成功!"; } else { echo "HTTP 输出字符编码设置失败!"; }

Output:

 HTTP 输出字符编码设置成功!

Notes:

  • The mb_http_output() function can only be used at the top of the script and is called before outputting anything.
  • The character encoding set by the mb_http_output() function will affect the subsequent output content, including echo, print and HTTP header information.
Similar Functions
Popular Articles