1. 程式人生 > >php 字串首字母ucfirst函式轉換成大寫

php 字串首字母ucfirst函式轉換成大寫

本文例項講述了php實現字串首字母轉換成大寫的方法。分享給大家供大家參考。具體分析如下:

php中可以通過ucfirst函式將一個字串中的第一個字母轉換成大寫,而ucwords函式可以將一個字串中每個單詞的首字母轉換成大寫

$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