{ucfirst:string}

Description

Uppercases the first character of a string and returns the result. Only the first character is changed - the rest of the string is left exactly as it is, it is NOT lowercased. This is the counterpart of the PHP function ucfirst. Use it to turn a stored lowercase value (a status key, a tag, a category slug) into a display label with an initial capital, for example draft becomes Draft. Related commands: ucwords uppercases the first letter of every word, lcfirst lowercases the first letter, strtolower and strtoupper change the whole string. Combine with strtolower when you want the rest of the text lowered before capitalizing the first letter. On a UTF-8 install the first character is uppercased with multibyte awareness, so a leading accented letter (an a-acute becomes A-acute) is handled correctly. The argument is not trimmed: a leading space is treated as the first character and stays a space.

Parameters

string optional default (empty string)

The text whose first character is uppercased. The rest of the string is returned unchanged - it is not lowercased. Leading whitespace is not trimmed, so a leading space stays the first character and is left as-is.

Examples

test{ucfirst:draft}
ExpectedDraft
ActualDraft
A common real-world use: turn a stored lowercase value (a status, tag, or category key) into a display label with an initial capital.
test{ucfirst:hello world}
ExpectedHello world
ActualHello world
The first character is uppercased; the rest of the string keeps its existing case. Only the very first character is touched.
test[{ucfirst:}]
Expected[]
Actual[]
With no argument the result is the empty string. The brackets are only shown here to make the empty result visible.
test{ucfirst:iPhone}
ExpectedIPhone
ActualIPhone
Only the leading character is affected: the i becomes I and the capital P inside the word is preserved. ucfirst never re-cases anything but the first character.
test{ucfirst:hELLO}
ExpectedHELLO
ActualHELLO
ucfirst does NOT lowercase the rest. Here the first letter is already-or-now uppercase and the remaining HELLO is left untouched. Use strtolower first if you want the rest lowered.