在php中,轉(zhuǎn)換首字母大寫(xiě)的函數(shù)是ucfirst(),該函數(shù)的作用就是將字符串的首字母轉(zhuǎn)化為大寫(xiě),語(yǔ)法“ucfirst(string)”。
本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版、DELL G3電腦
在php中,想要轉(zhuǎn)換首字母大寫(xiě),可以使用ucfirst()函數(shù)。(相反,想要轉(zhuǎn)換首字母小寫(xiě),可以使用lcfirst()函數(shù)。)
ucfirst 函數(shù)能夠?qū)⒆址牡谝粋€(gè)字母轉(zhuǎn)化為大寫(xiě)。語(yǔ)法格式如下:
ucfirst($string)
其中,$string 為需要轉(zhuǎn)化的字符串。
示例:
<?php $str = 'hello world!'; $str = ucfirst($str); echo $str.'<br>'; $str2 = 'HELLO WORLD!'; $str2 = ucfirst(strtolower($str2)); echo $str2; ?>
輸出結(jié)果:
Hello world! Hello world!
推薦學(xué)習(xí):《PHP視頻教程》