PHP - Update first character to upper using ucfirst

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 Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter e2e1e in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |