Current Location: Home> Function Categories> mb_detect_order

mb_detect_order

Set/get the detection order of character encoding
Name:mb_detect_order
Category:Multi-byte string
Programming Language:php
One-line Description:Set the character encoding order for multibyte character detection

Function name: mb_detect_order()

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

Function description: mb_detect_order() function is used to set the character encoding order of multibyte character detection. It determines the priority when detecting character encoding using mb_detect_encoding().

Syntax: mb_detect_order([string $encoding_list = mb_detect_order()])

parameter:

  • encoding_list (optional): A comma-separated character encoding list. The default value is the current character encoding order obtained by mb_detect_order().

Return value: Return true if successful; otherwise return false.

Example:

 // 设置字符编码顺序为UTF-8, GBK, ASCII mb_detect_order("UTF-8, GBK, ASCII"); // 检测字符串的字符编码$encoding = mb_detect_encoding("你好", mb_detect_order(), true); echo $encoding; // 输出:UTF-8

In the example above, we first use the mb_detect_order() function to set the character encoding order to UTF-8, GBK, ASCII. We then use the mb_detect_encoding() function to detect the character encoding of the string "Hello" and store the result in the $encoding variable. Finally, we use the echo statement to output the value of $encoding, with the result "UTF-8", indicating that the detected character encoding is UTF-8.

Please note that the character encoding order set by the mb_detect_order() function will affect the subsequent character encoding detection results using the mb_detect_encoding() function.

Similar Functions
Popular Articles