在PHP中,可以使用ucwords()函數(shù)將單詞首字母進行大寫轉(zhuǎn)換;該函數(shù)的作用是把字符串中每個單詞的首字母轉(zhuǎn)換為大寫,其語法為“ucwords(str)”,其參數(shù)str表示要轉(zhuǎn)換的字符串,使用時只需將字符串傳入str即可。
本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦
在PHP中,可以使用ucwords()函數(shù)將單詞首字母進行大寫轉(zhuǎn)換。
ucwords() 函數(shù)把字符串中每個單詞的首字符轉(zhuǎn)換為大寫。
注釋:該函數(shù)是二進制安全的。
語法
ucwords(string)
參數(shù)string :必需。規(guī)定要轉(zhuǎn)換的字符串。
返回值:返回已轉(zhuǎn)換的字符串。
代碼示例:
<?php $foo = 'hello world!'; $foo = ucwords($foo); // Hello World! echo $foo."<br>"; $bar = 'HELLO WORLD!'; $bar = ucwords($bar); // HELLO WORLD! echo $bar."<br>"; $bar = ucwords(strtolower($bar)); // Hello World! echo $bar; ?>
輸出:
Hello World! HELLO WORLD! Hello World!
推薦學(xué)習(xí):《PHP視頻教程》