查詢

IntlChar::totitle()函式—用法及示例

「 將給定的Unicode字元轉換為其標題大小寫形式 」


IntlChar::totitle()函式用於將給定的Unicode字元轉換為其標題大小寫形式。

用法:

IntlChar::totitle(mixed $codepoint): mixed

引數:

  • $codepoint:要轉換的Unicode字元(整數或字串)。可以是十進位制、十六進位制或Unicode字元的名稱。

返回值: 返回轉換後的標題大小寫形式的Unicode字元。

示例:

// 轉換單個字元
echo IntlChar::totitle(97); // 輸出:A

// 轉換字串
$string = "hello world";
$convertedString = "";
for ($i = 0; $i < strlen($string); $i++) {
    $convertedString .= IntlChar::totitle($string[$i]);
}
echo $convertedString; // 輸出:Hello World

// 轉換Unicode字元的名稱
$codepoint = IntlChar::charName('@');
$convertedCodepoint = IntlChar::totitle($codepoint);
echo $convertedCodepoint; // 輸出:COMMERCIAL AT

注意:

  • IntlChar類位於IntlChar擴充套件中,因此在使用該函式之前,需要確保已安裝並啟用了該擴充套件。
  • 該函式在PHP 7.0.0及以上版本可用。
補充糾錯
上一個函式: IntlChar::toupper()函式
下一個函式: IntlChar::tolower()函式
熱門PHP函式
分享連結