PHP - Update first character to upper using ucfirst

by
Jeremy Canfield |
Updated: October 07 2022
| PHP articles
ucfirst can be used to update a string so that the first character is upper case. For example, let's say you have a variable that contains the text hello world.
$string = "hello world";
In this example, the first character in $string will be updated to upper.
$string = ucfirst($string);
Now, when you echo $string. . .
echo $string;
. . . the following will be displayed.
Hello world
Optionally, you could also use strtolower to first update the string to all lower case to guarantee that only the first character is upper.
$string = strtolower(ucfirst($string));
Did you find this article helpful?
If so, consider buying me a coffee over at