ucfirst
Makes the first letter of a string uppercase.
Available since: PHP 4
Syntax
ucfirst(string $string): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The source string. |
Return value
stringThe string with its first letter uppercased.
Examples
An ASCII string:
<?php
echo ucfirst('hello world');Output:
Hello worldThe function does not change Cyrillic:
<?php
echo ucfirst('привет');Output:
приветPHP 8.4 adds mb_ucfirst() for any alphabet:
<?php
echo mb_ucfirst('привет');Output:
ПриветNotes
The other letters are left as they are: ucfirst('hELLO') returns HELLO. To capitalise the first letter of every word, use ucwords().
See also
- mb_strtoupper — Converts a string to uppercase.
Related recipes
In the tutorial
- Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.