PHP mb_convert_case mbstring 函數

定義和用法

mb_convert_case - 對字符串進行大小寫轉換

語法

mb_convert_case( string $str , int $mode [, string $encoding = mb_internal_encoding() ] )

mb_convert_case() 對一個 string 進行大小寫轉換,轉換模式由 mode 指定。

參數

參數必需的描述
str要被轉換的字符串
mode轉換的模式。它可以是 MB_CASE_UPPER、 MB_CASE_LOWER 和 MB_CASE_TITLE 的其中一個。
encodingencoding 參數爲字符編碼。如果省略,則使用內部字符編碼。

返回值

按 mode 指定的模式轉換 string 大小寫後的版本。

和類似 strtolower()strtoupper() 的標準大小寫轉換函數相比, 大小寫轉換的執行根據 Unicode 字符屬性的基礎。 因此此函數的行爲不受語言環境(locale)設置的影響,能夠轉換任意具有“字母”屬性的字符,例如元音變音A(Ä)。

示例

$str = "mary had a Little lamb and she loved it so";
$str = mb_convert_case($str, MB_CASE_UPPER, "UTF-8");
echo $str; // 輸出 MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
$str = mb_convert_case($str, MB_CASE_TITLE, "UTF-8");
echo $str; // 輸出 Mary Had A Little Lamb And She Loved It So

相關頁面

mb_strtolower() - 使字符串小寫

mb_strtoupper() - 使字符串大寫

strtolower() - 將字符串轉化爲小寫

strtoupper() - 將字符串轉化爲大寫

ucfirst() - 將字符串的首字母轉換爲大寫

ucwords() - 將字符串中每個單詞的首字母轉換爲大寫


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章