ucwords() uppercases the first ASCII lowercase character after each delimiter (including at the beginning of the string). You can optionally provide a custom separator list.
$text = 'php string functions';
echo ucwords($text); // Php String Functions
$str="welcome to plus2net.com. you can learn web programming here";
$str=ucwords($str);
echo $str;
The output is here
Welcome To Plus2net.com. You Can Learn Web Programming Here
Syntax
$input_str = "welcome everyone";
$output = ucwords($input_str);
echo $output; // Welcome Everyone
| Parameter | DESCRIPTION |
|---|---|
$input_str | Required : Input string |
$delimiters | Optional : contains the word separator characters. |
$my_str="hello,welcome";
echo ucwords($my_str,',');
Output is here
Hello,Welcome
Here, only the vertical bar is specified as a delimiter, so the comma does not trigger capitalization.
$my_str="hello,welcome|home";
echo ucwords($my_str,'|');
Output is here
Hello,welcome|Home
Both the comma and vertical bar act as delimiters in this example.
$my_str="hello,welcome|home";
echo ucwords($my_str,'|,');
Output is here
Hello,Welcome|Home
Enter a string to see the converted result. The submitted value is escaped before it is returned to this HTML page.
$str = 'hello-world_php-tutorial';
echo ucwords($str, "-_"); // Output: Hello-World_Php-Tutorial
ucwords() is ASCII-oriented. For Unicode title casing, use mb_convert_case() if mbstring is installed; title-casing rules vary by language.
$str = 'привет мир';
echo mb_convert_case($str, MB_CASE_TITLE, "UTF-8"); // Outputs: Привет Мир (with mbstring)
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.