How to Capitalize Each Word of a String in PHP 


               


How to Capitalize Each Word of a String in PHP

PHP


In this article, we go over how to capitalize each (and every) word in a string using the ucwords() function.

The ucwords() function capitalizes the first letter of all the words in a string.

So, if we have the string "wild at heart", after passing it through the ucwords() function, the string would then change to "Wild at Heart".

Example

Below is an example of the Ucwords() function in action.



Actual PHP Output

Wild At Heart





The ucwords() function is the function to use when you want to capitalize the first letter of all the words in a string. This is useful for such strings as headlines or titles of articles or books, where all words are usually capitalized.

HTML Comment Box is loading comments...