PHP ucwords() Function

PHP ucwords() Function

The ucwords() function in PHP converts the first character of each word in the specified string to uppercase. It is a binary-safe function.

The related function are as follows:

  • ucfirst()
  • lcfirst()
  • strtoupper()
  • strtolower()

Syntax

ucwords ( string $str [, string $delimiters ] )

Parameter

str(required)- This parameter represents the input string.

delimeters(optional)- This parameter contains the word separator characters i.e ‘\t, \r, \n, \f, \v’.

Return

This parameter returns a string with the first character of each word in the specified string capitalized if that character is alphabetic.

Example 1

 

Output

Actual String: pHP is an easy language to learn.
After ucwords() function...
New string: PHP Is An Easy Language To Learn. 

Example 2

 

Output

After ucwords() Function...
 The Places To Visit In India Are As Follow: 
 Taj mahal
 Lotus temple
 Akshardham temple 

Example 3

 

Output

Original string: HELLO WORLD! NICE TO MEET YOU
After ucwords() Function...
New String: Hello World! Nice To Meet You 

Example 4

 

Output

Original string: hello|world!|how|are|you|today?
After ucwords() Function...
New String: Hello|World!|How|Are|You|Today?