What is the use of ucwords() PHP String function?

ucwords() changes the first letter of each word of a string to a capital letter. The rest of the letters are not changed.

<?php
echo ucwords("hello world from php") . "<br>";

// Different word separator
echo ucwords("hello-world foo", "-") . "<br>";

// Make the other letters small first
echo ucwords(strtolower("PHP TUTORIAL"));
?>

Output:

Tutorials Class - Output Window

Hello World From Php
Hello-World foo
Php Tutorial

By default words are separated by a space, tab or new line. Use the second parameter to give your own separators. To change only the first letter of the whole string use ucfirst().


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.