ucfirst

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

ucfirst將字符串的首字母轉(zhuǎn)換為大寫

說明

ucfirst(string $str): string

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

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

參數(shù)

str

輸入字符串。

返回值

返回結(jié)果字符串。

范例

示例 #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!
?>

參見

  • lcfirst() - 使一個字符串的第一個字符小寫
  • strtolower() - 將字符串轉(zhuǎn)化為小寫
  • strtoupper() - 將字符串轉(zhuǎn)化為大寫
  • ucwords() - 將字符串中每個單詞的首字母轉(zhuǎn)換為大寫