Friday, October 10, 2025
HomeLanguagesPHP mb_detect_order() Function

PHP mb_detect_order() Function

The mb_detect_order() function is an inbuilt function in PHP that is utilized to set or get the character encoding detection order.

Syntax:

mb_detect_order(array|string|null $encoding = null): array|bool

Parameters:  This function has only one parameter.

  • encoding: This parameter returns the current character encoding detection order as an array if the encoding is omitted or null.

Return Value: This function returns true when setting encoding detection order otherwise it will return false.

Example 1: The following code demonstrates the mb_detect_order() function.

PHP




<?php
  
// Set detection order
mb_detect_order("UTF-8, ASCII");
  
// Use mb_detect_encoding() to detect 
// encoding of string
$string = "neveropen";
$encoding = mb_detect_encoding($string);
  
// Output encoding
echo "Detected encoding: $encoding";
?>


Output:

Detected encoding: UTF-8

Example 2: The following code demonstrates the mb_detect_order() function.

PHP




<?php
  
/* Set detection order by enumerated list */
mb_detect_order("eucjp-win,sjis-win,UTF-8");
  
/* Set detection order by array */
$ary[] = "ASCII";
$ary[] = "JIS";
$ary[] = "EUC-JP";
mb_detect_order($ary);
  
/* Display current detection order */
echo implode(", ", mb_detect_order());
?>


Output:

ASCII, JIS, EUC-JP 

Reference: https://www.php.net/manual/en/function.mb-detect-order.php

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7100 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS