ucwords() :Converting the first letter to upper case of each word

Uppercase the first character of each word

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
ParameterDESCRIPTION
$input_strRequired : Input string
$delimitersOptional : contains the word separator characters.

With delimiters

Here, a comma separates words.
$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

Try ucwords() with your own text

Enter a string to see the converted result. The submitted value is escaped before it is returned to this HTML page.

Result:


Example: Capitalizing Words with Custom Delimiters

$str = 'hello-world_php-tutorial';
echo ucwords($str, "-_");  // Output: Hello-World_Php-Tutorial

Example: Unicode title casing (mbstring)

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)

String Functions ucfirst(): To Change first char only to upper case of a string. how to change all the letters to upper case


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer