The ucwords()
method in PHP makes the initial character of every word in a string uppercase.
The following figure shows a visual representation of the ucwords()
function.
ucwords(str, sep)
# where str stands for string and sep stands for separator
The ucwords()
function requires two parameters:
The ucwords()
uppercases the initial
character of every word in a string.
- The rest of the string, i.e., other than the first character of every word, stays the same.
- If the first character of the word is not a letter, then that word of the string remains the same.
The code below shows how the ucwords()
function works.
<?php#stringecho("ucwords('edpresso shots'): ");echo (ucwords('edpresso shots'));echo("\n");#string with numberecho("ucwords('hellO studentS of course 202'): ");echo (ucwords('hellO studentS of course 202'));echo("\n");#string with number along with separatorecho("ucwords('dev,tech,non-tech',','): ");echo (ucwords('dev,tech,non-tech',','));?>