PHP 8 reference · String Functions

PHP ucwords() Function

Uppercase the first letter of each word in a string. By default words are separated by spaces, tabs and new lines.

PHP 8 Since 4.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

ucwords(string $string, string $separators = " \t\r\n\f\v"): string

Parameters

ParameterDescription
string The input string.
separators optional Characters that start a new word. Default: " \t\r\n\f\v"

Return value

The string with each word capitalized.

Examples

Title caseTry it yourself
<?php
echo ucwords("the old man and the sea"), "\n";
echo ucwords(strtolower("JOHN O'REILLY")), "\n"; // ' isn't a separator

Output

The Old Man And The Sea
John O'reilly
Custom separatorsTry it yourself
<?php
echo ucwords("mary-jane watson", " -"), "\n";
echo ucwords("first_name", "_"), "\n";

Output

Mary-Jane Watson
First_Name

Version history

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?