What is ucword() in PHP?
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.
Syntax
ucwords(str, sep)
# where str stands for string and sep stands for separator
Parameter
The ucwords() function requires two parameters:
- A string
- A
separator This is an optional parameter. This character separates the words in a string. Its default value is " ".
Return value
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.
Code
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',','));?>