ucwords – PHP String Functions
Syntax :
Description :
ucwords() function will take string as input and converts first letter of every word in a string to uppercase letter, if that character is alphabetic. In general language, its name implies UC = Upper Case the words.
Parameter :
- string – This is a Required parameter. This is a string on which function will be performed.
- seperator/delimiters – This is a Optional parameter. It contains the word separator characters. By default these characters are
- space
- \t : tab
- \r : carriage return
- \n : newline
- \f : form feed
- \v : vertical tab
ChangeLog :
[table caption=”” width=”100%” colwidth=”50%|50%” colalign=”left|left”]
Version, Description
5.4.32 & 5.5.16, Added the delimiters parameter.
[/table]
Output :
This will return a changed string.
Related articles : strtolower(), strtoupper(), ucfirst(), lcfirst().
ucwords() – PHP Functions Example 1 :
<?php $strExample = "An example of a ucwords() function."; echo ucwords($strExample); ?>
In above example ,We have a string ‘An example of a ucwords() function’. Now this function will converts every first letter in a word to Uppercase. See below is the output of above code.
ucwords() – PHP Functions Example 2 :
<?php $strExample = "AN Example Of A ucwords() function WITH 789789."; echo ucwords($strExample); ?>
In above example ,We have a string ‘AN Example Of A ucwords() function WITH 789789.’. Now this function will converts every first letter in a word to Uppercase, it will not do anything with numeric numbers. See below is the output of above code.
ucwords() – PHP Functions Example 3 :
If you want to apply ucwords function on the basis of some separator. Use below example :
<?php $strExample ="an example |of a ucwords() |function."; echo ucwords($strExample,"|"); ?>
Output will be like below: