Home »
PHP
PHP ucwords() Function with Example
By IncludeHelp Last updated : December 27, 2023
PHP ucwords() Function
The ucwords() function is a string function in PHP and it is used to converts the first characters in uppercase of all words in a string.
Syntax
The syntax of the ucwords() function:
ucwords(string);
Parameters
The parameters of the ucwords() function:
- string: It accepts a string as an input parameter.
Return Value
The return value of this method is string, it returns the new string with first character of the words in uppercase.
Sample Input/Output
Input: "hello world how are you?"
Output: "Hello World How Are You?"
Input: "hello123"
Output: "Hello123"
Example of PHP ucwords() Function
<?php
$str = "hello world how are you?";
echo (ucwords($str) . "\n");
$str = "HELLO world how are you?";
echo (ucwords($str) . "\n");
$str = "hello123 123hello";
echo (ucwords($str) . "\n");
?>
Output
The output of the above example is:
Hello World How Are You?
HELLO World How Are You?
Hello123 123hello
To understand the above example, you should have the basic knowledge of the following PHP topics: