PHP - Update first character of each word to upper using ucwords

ucwords can be used to update one or more words so that the first character is upper case. For example, let's say you have a variable that contains the text hello world.

$words = "hello world";


In this example, the $words will be updated to upper.

$words = ucwords($words);


Now, when you echo $words. . .

echo $words;


. . . 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 of each word is upper.

$words = strtolower(ucwords($words));


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 8c8da in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |