ucwords

Uppercase the first character of each word in a string

Syntax

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

Parameters

string

The input string.

separators

The optional separators contains the word separator characters.

"\t" ASCII 9 (0x09) a tab
"\n" ASCII 10 (0x0A) a new line (line feed)
"\v" ASCII 11 (0x0B) a vertical tab
"\f" ASCII 12 (0x0C) a form feed
"\r" ASCII 13 (0x0D) a carriage return
" " ASCII 32 (0x20) an ordinary space

Return

Returns the modified string.

Examples

1

<?

$string = "case case";

$return = ucwords($string);

echo $return;

?>
Case Case

2

<?

$string = "case|case";
$separators = "|";

$return = ucwords($string, $separators);

echo $return;

?>
Case|Case

3

<?

$string = "case\tcase\ncase\vcase\fcase\rcase case";
$separators = " \t\r\n\f\v";

$return = ucwords($string, $separators);

echo $return;

?>
Case    Case
CaseCaseCase
Case Case

4

<?

$string = "case#case%case&case,case'case|case";
$separators = "#%&,'|";

$return = ucwords($string, $separators);

echo $return;

?>
Case#Case%Case&Case,Case'Case|Case

5

<?

$string = "case\tcase\ncase\vcase\fcase\rcase case#case%case&case,case'case|case";
$separators = " \t\r\n\f\v#%&,'|";

$return = ucwords($string, $separators);

echo $return;

?>
Case    Case
CaseCaseCase
Case Case#Case%Case&Case,Case'Case|Case

Internal

lcfirst

ucfirst

External

PHP

Home Menu