PHP – How to set the character encoding detection order using mb_detect_order()?

PHPServer Side ProgrammingProgramming

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

Syntax

array|bool mb_detect_order(str $encoding)

Parameters

mb_detect_order() accepts only one parameter $encoding with string, array and bool.

  • $encoding− This encoding parameter is an array or comma-separated list of character encoding. If it is omitted or null, then it returns the current character encoding detection order as an array.

Return Values

When setting the encoding detection order, it returns True on success or it returns False on failure.

Example

 Live Demo

<?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
raja
Published on 23-Aug-2021 08:25:53

Advertisements