ucwords
Uppercases the first letter of every word.
Syntax
ucwords(string $string, string $separators = " \t\r\n\f\v"): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The source string. |
| $separators | string | Optional. 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 SmithA custom separator:
<?php
echo ucwords('anna-maria smith', '-');Output:
Anna-Maria smithNotes
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.