本文目錄一覽:
- 1、PHP中怎樣將字元串每個單詞的首字元轉換成大寫
- 2、PHP怎麼實現大小寫轉換
- 3、php如何創建包含所有大寫字母的數組
- 4、php中把字元串首字母轉大寫方法?
- 5、PHP里,怎麼將數組裡的字元串的字母轉換為大寫
- 6、PHP 中文轉拼音並首字母大寫
PHP中怎樣將字元串每個單詞的首字元轉換成大寫
php中可以通過ucfirst函數將一個字元串中的第一個字母轉換成大寫,而ucwords函數可以將一個字元串中每個單詞的首字母轉換成大寫
?php
$string = “php string functions are easy to use.”;
$sentence = ucfirst($string);
$title = ucwords($string);
print(“$sentence\n”);
print(“$title\n”);
print(“\n”);
?
輸出結果如下:
Php string functions are easy to use.
Php String Functions Are Easy To Use
PHP怎麼實現大小寫轉換
php內置有大小寫轉換函數。
strtolower 將字元串轉換為小寫
strtoupper 將字元串轉換為大寫
php如何創建包含所有大寫字母的數組
新建一個php文件,命名為test.php,用於講解php如何將數組中所有字母改為大寫。
請點擊輸入圖片描述
在test.php文件中,使用header()方法將頁面的編碼格式設置為utf-8。
請點擊輸入圖片描述
在test.php文件中,定義一個changeAbc函數,使用strtoupper函數將傳入的參數轉換為大寫字母,並使用return將參數返回。
請點擊輸入圖片描述
在test.php文件中,創建一個小寫字母數組,用於測試。
請點擊輸入圖片描述
在test.php文件中,使用array_map函數使用函數changeAbc對數組進行轉換大寫字母處理,最後,使用print_r輸出結果。
請點擊輸入圖片描述
在瀏覽器打開test.php文件,查看結果。
請點擊輸入圖片描述
php中把字元串首字母轉大寫方法?
strtoupper
(PHP 4, PHP 5, PHP 7)
strtoupper — 將字元串轉化為大寫
說明
strtoupper ( string $string ) : string
將 string 中所有的字母字元轉換為大寫並返回。
注意 「字母」 與當前所在區域有關。例如,在默認的 「C」 區域,字元 umlaut-a(ä)就不會被轉換。
參數
string
輸入字元串。
返回值
返迴轉換後的大寫字元串。
範例
Example #1 strtoupper() 範例
注釋
Note: 此函數可安全用於二進位對象。
參見
strtolower() – 將字元串轉化為小寫
ucfirst() – 將字元串的首字母轉換為大寫
ucwords() – 將字元串中每個單詞的首字母轉換為大寫
mb_strtoupper() – 使字元串大寫
PHP里,怎麼將數組裡的字元串的字母轉換為大寫
array_walk 多維數組試試 array_walk_recursive
?php
$a = array(“aa”,”bb”,’cc’);
array_walk($a,function($v,$k){$v = strtoupper($v);});
print_r($a);
PHP 中文轉拼音並首字母大寫
?php
function getfirstchar($s0){
$fchar = ord($s0{0});
if($fchar = ord(“A”) and $fchar = ord(“z”) )return strtoupper($s0{0});
$s1 = iconv(“UTF-8″,”gb2312”, $s0);
$s2 = iconv(“gb2312″,”UTF-8”, $s1);
if($s2 == $s0){$s = $s1;}else{$s = $s0;}
$asc = ord($s{0}) * 256 + ord($s{1}) – 65536;
if($asc = -20319 and $asc = -20284) return “A”;
if($asc = -20283 and $asc = -19776) return “B”;
if($asc = -19775 and $asc = -19219) return “C”;
if($asc = -19218 and $asc = -18711) return “D”;
if($asc = -18710 and $asc = -18527) return “E”;
if($asc = -18526 and $asc = -18240) return “F”;
if($asc = -18239 and $asc = -17923) return “G”;
if($asc = -17922 and $asc = -17418) return “H”;
if($asc = -17417 and $asc = -16475) return “J”;
if($asc = -16474 and $asc = -16213) return “K”;
if($asc = -16212 and $asc = -15641) return “L”;
if($asc = -15640 and $asc = -15166) return “M”;
if($asc = -15165 and $asc = -14923) return “N”;
if($asc = -14922 and $asc = -14915) return “O”;
if($asc = -14914 and $asc = -14631) return “P”;
if($asc = -14630 and $asc = -14150) return “Q”;
if($asc = -14149 and $asc = -14091) return “R”;
if($asc = -14090 and $asc = -13319) return “S”;
if($asc = -13318 and $asc = -12839) return “T”;
if($asc = -12838 and $asc = -12557) return “W”;
if($asc = -12556 and $asc = -11848) return “X”;
if($asc = -11847 and $asc = -11056) return “Y”;
if($asc = -11055 and $asc = -10247) return “Z”;
return null;
}
function make_semiangle($str){
$arr = array(‘0’ = ‘0’, ‘1’ = ‘1’, ‘2’ = ‘2’, ‘3’ = ‘3’, ‘4’ = ‘4’, ‘5’ = ‘5’, ‘6’ = ‘6’, ‘7’ = ‘7’, ‘8’ = ‘8’, ‘9’ = ‘9’, ‘A’ = ‘A’, ‘B’ = ‘B’, ‘C’ = ‘C’, ‘D’ = ‘D’, ‘E’ = ‘E’, ‘F’ = ‘F’, ‘G’ = ‘G’, ‘H’ = ‘H’, ‘I’ = ‘I’, ‘J’ = ‘J’, ‘K’ = ‘K’, ‘L’ = ‘L’, ‘M’ = ‘M’, ‘N’ = ‘N’, ‘O’ = ‘O’, ‘P’ = ‘P’, ‘Q’ = ‘Q’, ‘R’ = ‘R’, ‘S’ = ‘S’, ‘T’ = ‘T’, ‘U’ = ‘U’, ‘V’ = ‘V’, ‘W’ = ‘W’, ‘X’ = ‘X’, ‘Y’ = ‘Y’, ‘Z’ = ‘Z’, ‘a’ = ‘a’, ‘b’ = ‘b’, ‘c’ = ‘c’, ‘d’ = ‘d’, ‘e’ = ‘e’, ‘f’ = ‘f’, ‘g’ = ‘g’, ‘h’ = ‘h’, ‘i’ = ‘i’, ‘j’ = ‘j’, ‘k’ = ‘k’, ‘l’ = ‘l’, ‘m’ = ‘m’, ‘n’ = ‘n’, ‘o’ = ‘o’, ‘p’ = ‘p’, ‘q’ = ‘q’, ‘r’ = ‘r’, ‘s’ = ‘s’, ‘t’ = ‘t’, ‘u’ = ‘u’, ‘v’ = ‘v’, ‘w’ = ‘w’, ‘x’ = ‘x’, ‘y’ = ‘y’, ‘z’ = ‘z’, ‘(’ = ‘(‘, ‘)’ = ‘)’, ‘〔’ = ‘[‘, ‘〕’ = ‘]’, ‘【’ = ‘[‘, ‘】’ = ‘]’, ‘〖’ = ‘[‘, ‘〗’ = ‘]’, ‘「’ = ‘”‘, ‘」’ = ‘”‘, ‘『’ = ‘\”, ‘』’ = ‘\”, ‘{’ = ‘{‘, ‘}’ = ‘}’, ‘《’ = ”, ‘》’ = ”, ‘%’ = ‘%’, ‘+’ = ‘+’, ‘—’ = ‘-‘, ‘-’ = ‘-‘, ‘~’ = ‘-‘, ‘:’ = ‘:’, ‘。’ = ‘.’, ‘、’ = ‘,’, ‘,’ = ‘,’, ‘;’ = ‘;’, ‘?’ = ‘?’, ‘!’ = ‘!’, ‘…’ = ‘…’, ‘‖’ = ‘|’, ‘|’ = ‘|’, ‘〃’ = ‘”‘, ‘ ’ = ‘ ‘);
return strtr($str, $arr);
}
function pinyin1($zh){
$zh = make_semiangle($zh);
$ret = “”;
$s1 = iconv(“UTF-8″,”gb2312”, $zh);
$s2 = iconv(“gb2312″,”UTF-8”, $s1);
if($s2 == $zh){$zh = $s1;}
for($i = 0; $i strlen($zh); $i++){
$s1 = substr($zh,$i,1);
$p = ord($s1);
if($p 160){
$s2 = substr($zh,$i++,2);
$ret .= getfirstchar($s2);
}else{
$ret .= $s1;
}
}
return $ret;
}
//用法
echo pinyin1(‘中文獲取首字母大寫,『支持』全形「的」轉化!’);
?
數字跟英文的全形被百度自動轉了,如果需要下載附件源碼
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/241845.html