Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

ucwords

Uppercases the first letter of every word.

Syntax

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

Parameters

ParameterTypeDescription
$stringstringThe source string.
$separatorsstringOptional. The characters treated as word separators.

Return value

stringThe string with the first letter of each word capitalized.

Examples

A first and last name:

<?php
 
echo ucwords('anna maria smith');

Output:

Anna Maria Smith

A custom separator:

<?php
 
echo ucwords('anna-maria smith', '-');

Output:

Anna-Maria smith

Notes

It works with ASCII letters only. The other letters of a word are not changed — if the string was in capitals, call strtolower() first.

See also

  • ucfirst — Makes the first letter of a string uppercase.
  • strtoupper — Converts ASCII letters to uppercase.

In the tutorial

  • Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.

Thanks for reading!

Donate to the site — we work hard for you.