PHP 8 reference · String Functions
PHP ucfirst() Function
Make the first character of a string uppercase and leave the rest as it is. Only ASCII letters change.
PHP 8 Since 4.0
Syntax
ucfirst(string $string): string
Parameters
| Parameter | Description |
|---|---|
string |
The input string. |
Return value
The string with its first character uppercased.
Examples
<?php
echo ucfirst("hello world"), "\n";
echo ucfirst("iPhone"), "\n";
Output
Hello world IPhone
<?php
$name = "mARY";
echo ucfirst(strtolower($name)), "\n"; // lowercase first for a clean result
Output
Mary
Version history
| Version | Change |
|---|---|
| PHP 4.0 | Added |
In other languages
str.capitalize()· Python
Related
lcfirst()· Make the first character of a string lowercase, leaving the rest unchanged. Handy for turning PascalCase into camelCase.ucwords()· Uppercase the first letter of each word in a string. By default words are separated by spaces, tabs and new lines.mb_ucfirst()· Make the first character of a string title case, including letters such as é or ı. Added in PHP 8.4.strtolower()· Convert every ASCII letter in a string to lowercase. Since PHP 8.2 it ignores the locale; use mb_strtolower() for é, Ü and others.- PHP Strings · tutorial