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

Updated:   |  PHP articles

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



Comments


Add a Comment


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