mb_http_input
Detect HTTP input character encoding
Function name: mb_http_input()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7
Function description: The mb_http_input() function is used to return the current HTTP input character encoding.
usage:
mb_http_input([string $type = ""]) : mixed
Parameter description:
$type
(optional): Specifies the HTTP input character encoding type to be returned. Optional values include "G", "P", "C", "S", "L" and "I". The default is an empty string.Return value:
$type
parameter is an empty string, the name (string) of the current HTTP input character encoding is returned.$type
parameter specifies a character encoding type, it returns whether the current HTTP input character encoding belongs to the specified character encoding type (Boolean).Example:
// 示例1:返回当前的HTTP 输入字符编码$inputEncoding = mb_http_input(); echo "当前的HTTP 输入字符编码是:$inputEncoding"; // 示例2:检查当前的HTTP 输入字符编码是否为UTF-8 $isUTF8 = mb_http_input("utf-8"); if ($isUTF8) { echo "当前的HTTP 输入字符编码是UTF-8"; } else { echo "当前的HTTP 输入字符编码不是UTF-8"; }
Notes:
mb_http_input()
function requires support for the mbstring extension. Make sure the mbstring extension is enabled in the PHP configuration file.mb_http_input()
function may not accurately detect HTTP input character encoding, and the return result may be inaccurate. It is recommended to use other methods to obtain character encoding, such as obtaining character encoding information in the HTTP request header through $_SERVER['HTTP_ACCEPT_CHARSET']
.