ucfirst

(PHP 4, PHP 5, PHP 7, PHP 8)

ucfirst將字符串的首字母轉換為大寫

說明

ucfirst(string $str): string

str 的首字符(如果首字符是字母)轉換為大寫字母,并返回這個字符串。

注意字母的定義取決于當前區(qū)域設定。例如,在默認的 “C” 區(qū)域,字符 umlaut-a(?)將不會被轉換。

參數(shù)

str

輸入字符串。

返回值

返回結果字符串。

范例

示例 #1 ucfirst() 范例

<?php
$foo 
'hello world!';
$foo ucfirst($foo);             // Hello world!

$bar 'HELLO WORLD!';
$bar ucfirst($bar);             // HELLO WORLD!
$bar ucfirst(strtolower($bar)); // Hello world!
?>

參見