PHP.nl

ucwords

ucwords

Uppercase the first character of each word in a string

string **ucwords** string $string string $separators

Returns a string with the first character of each word in capitalized, if that character is an ASCII character between (0x61) and (0x7a). string``"a"``"z"

For this function, a word is a string of characters that are not listed in the parameter. By default, these are: space, horizontal tab, carriage return, newline, form-feed and vertical tab. separators

To do a similar conversion on multibyte strings, use with the mode. mb_convert_case``MB_CASE_TITLE

stringThe input string.

separators The optional contains the word separator characters. separators

Returns the modified string.

Voorbeeld: example

<?php
$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!
?>

Voorbeeld: example with custom delimiter

<?php
$foo = 'hello|world!';
echo ucwords($foo), PHP_EOL;             // Hello|world!

echo ucwords($foo, "|"), PHP_EOL;        // Hello|World!
?>

Voorbeeld: example with additional delimiters

<?php
$foo = "mike o'hara";
echo ucwords($foo), PHP_EOL;                 // Mike O'hara

echo ucwords($foo, " \t\r\n\f\v'"), PHP_EOL; // Mike O'Hara
?>

strtoupper``strtolower``ucfirst``mb_convert_case