php中首字母小寫轉大寫的函數(shù):1、ucfirst()函數(shù),可將字符串的首字母轉換成大寫,語法“ucfirst($str)”;2、ucwords()函數(shù),可將字符串中每個單詞的首字母轉換為大寫,語法“ucwords($str)”。
本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版、DELL G3電腦
php中首字母小寫轉大寫的函數(shù)有兩種:
-
ucfirst()函數(shù),可將字符串的首字母轉換成大寫
-
ucwords()函數(shù),可將字符串中每個單詞的首字母轉換為大寫
1、ucfirst()函數(shù)
ucfirst() 函數(shù)把字符串中的首字符轉換為大寫。
示例:
<?php echo ucfirst("hello world!"); ?>
2、ucwords()函數(shù)
ucwords() 函數(shù)把字符串中每個單詞的首字符轉換為大寫。
語法:
ucwords($string [, $delimiters = "trnfv" ])
其中,$string 為需要轉化的字符串;$delimiters 為可選參數(shù),用來表示單詞分隔符,默認是空格符、制表符、換行符、回車符、水平線以及豎線。
示例:
<?php $foo = 'hello world!'; $foo = ucwords($foo); // Hello World! echo $foo."<br>"; $foo = 'hello|world!'; $bar = ucwords($foo); // Hello|world! echo $bar."<br>"; $baz = ucwords($foo,"|"); // Hello|World! echo $baz."<br>"; ?>
輸出:
Hello World! Hello|world! Hello|World!
推薦學習:《PHP視頻教程》