ucwords()
ucwords() — Uppercase the first character of each word in a string.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns a string with the first character of each word in string capitalized, if that character is an ASCII character between "a" (0x61) and "z" (0x7a).
Signature
ucwords(string $string, string $separators = " \t\r\n\f\v"): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The input string. |
| $separators | string | The optional separators contains the word separator characters. |
Return value
Returns the modified string.
Example
A runnable snippet:
$foo = 'hello world!'; echo ucwords($foo), PHP_EOL; // Hello World! $bar = 'HELLO WORLD!'; echo ucwords($bar), PHP_EOL; // HELLO WORLD! echo ucwords(strtolower($bar)), PHP_EOL; // Hello World!
Changelog
| Version | Change |
|---|---|
| 8.2.0 | Case conversion no longer depends on the locale set with setlocale(). Only ASCII characters will be converted. |
See also
strtoupper(), strtolower(), ucfirst(), mb_convert_case()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page ucwords() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.