PHP – 如何使用 mb_detect_order() 設定字元編碼檢測順序?


PHP 中的 mb_detect_order() 函式可用於按順序設定/獲取字元編碼檢測。此函式在 PHP 4.2.0 或更高版本中受支援。

語法

array|bool mb_detect_order(str $encoding)

引數

mb_detect_order() 僅接受一個引數 $encoding,其中包含 字串陣列布林值

  • $encoding− 此編碼引數是字元編碼的陣列或逗號分隔列表。如果省略此編碼或其值為 null,則返回當前字元編碼檢測順序(形式為陣列)。

返回值

設定編碼檢測順序時,如果成功返回 True,如果失敗返回 False。

示例

 線上示例

<?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());
?>

輸出

ASCII, JIS, EUC-JP

更新日期:2021 年 8 月 23 日

163 次瀏覽

職業生涯啟航

完成課程,獲得認證

立即開始
廣告
© . All rights reserved.