php 字串大小寫轉換

2021-07-25 05:02:03 字數 1164 閱讀 4147

mb_convert_case

mb_convert_case —對字串進行大小寫轉換

mb_convert_case ( string

$str , int

$mode [, string

$encoding = mb_internal_encoding() ] )

對乙個 string 進行大小寫轉換,轉換模式由 mode 指定。

引數 :

str 要被轉換的 string。

mode 轉換的模式。它可以是 mb_case_upper、 mb_case_lower 和 mb_case_title 的其中乙個。

mb_case_upper : 字串全部大寫

mb_case_lower : 字串全部小寫

mb_case_title : 字串各單詞首字母大寫

encoding 引數為字元編碼。如果省略,則使用內部字元編碼。

返回值 :

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

注意:

和類似 strtolower()、strtoupper() 的標準大小寫轉換函式相比, 大小寫轉換的執行根據 unicode 字元屬性的基礎。 因此此函式的行為不受語言環境(locale)設定的影響,能夠轉換任意具有「字母」屬性的字元,例如母音變音a(ä)。
範例:

<?php

$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

?>

大小寫轉換 字串

time limit 1000ms memory limit 65536kb problem description 把乙個字串裡所有的大寫字母換成小寫字母,小寫字母換成大寫字母。其他字元保持不變。input 輸入為一行字串,其中不含空格。長度不超過80個字元。output 輸出轉換好的字串。exa...

PHP 字元轉換大小寫

將字串轉化為小寫 str abcdef echo strtolower str 輸出 aabcdef 將字串轉化為大寫 str abcdefd echo strtoupper str 輸出 abcdefd 使字元的第乙個字母小寫 echo lcfirst hello world 輸出 hello w...

std string 字串大小寫轉換

該問題歸結為std transform 函式的使用 函式原型 template class inputiterator,class outputiterator,class unaryoperator outputiterator transform inputiterator first1,inp...