Home  >  Article  >  Backend Development  >  PHP - How to set character encoding detection order using mb_detect_order() function?

PHP - How to set character encoding detection order using mb_detect_order() function?

WBOY
WBOYforward
2023-09-01 20:45:021003browse

PHP - 如何使用mb_detect_order()函数设置字符编码检测顺序?

The mb_detect_order() function in PHP can be used to set/get character encoding detection in order. This function is supported in PHP 4.2.0 or higher.

Syntax

array|bool mb_detect_order(str $encoding)

Parameters

mb_detect_order()Accepts only one parameter $encoding, which can be a string , Array or Boolean value.

  • $encoding− The encoding parameter can be an array or a comma-separated list of character encodings. If omitted or null, returns an array in the current character encoding detection order.

Return value

When setting the encoding detection sequence, True is returned on success and False on failure.

Example

Demonstration

<?php
   // Set detection order by enumerated list
   mb_detect_order("eucjp-win,sjis-win,UTF-8");

   // Set detection order by array
   $array[] = "ASCII";
   $array[] = "JIS";
   $array[] = "EUC-JP";
   mb_detect_order($array);

   // It shows the current detection order
   echo implode(", ", mb_detect_order());
?>

Output

ASCII, JIS, EUC-JP

The above is the detailed content of PHP - How to set character encoding detection order using mb_detect_order() function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete