2010-03-25 105 views
5

PHP中是否有任何函數使字的第一個字符大寫, 或者我應該用正則表達式來編寫它?如何使單詞的第一個字符大寫?

+5

我輸入'php upper',Google建議我搜索'php uppercase first letter'。第一擊是ucfirst功能。谷歌,然後問;) – 2010-03-25 14:29:48

回答

11

使用ucfirst函數。

+0

擊敗我五秒。嘿。 – 2010-03-25 14:26:29

+0

啊,這是如此簡單:)謝謝 – Simon 2010-03-25 14:28:08

+0

在旁註ucfirst依賴於語言環境,所以看你的步驟 – 2010-03-25 14:38:39

4
$word = ucfirst($word); 
0

嘗試使用ucwords()函數。

+0

ucwords()將大寫字母中的每個單詞,而不僅僅是第一個字母。也許這就是原來的海報想要的,不確定。投票贊成有疑問。 – 2010-03-25 14:30:25

1

$ firstlettersuppercased = ucwords($originalstring);

這將大寫每個單詞在$ originalstring的第一個字母。

1
$word_ = "your name here"; 
echo ucfirst($word_); // Your name here 
echo ucwords($word_); // Your Name Here 
相關問題