ucwords() function in PHP


The ucwords() function is used to convert the first character of a string to uppercase in each string.

Syntax

ucwords(str)

Parameters

  • str − The specified string

Return

The ucfirst() function returns the converted string.

Example

The following is an example −

 Live Demo

<?php
   echo ucwords("This is it!");
?>

Output

The following is the output −

This Is It!

Example

Let us see another example −

 Live Demo

<?php
   $s = "#demo#text";
   $sep = '$';
   $res = ucwords($s, $sep);
   print_r($res);
?>

Output

The following is the output −

#demo#text

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Dec-2019

117 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements