PHP ucwords() Function

Last updated on March 13, 2023

In PHP, the ucwords() function converts the first letter of each word into uppercase. It takes one required parameter. For example if you pass a string value “programming language” into the ucwords() function then it would return “Programming Language”.

Syntax

ucwords(string $anyString)

Parameters

It takes one required parameter. The should be string so that function can convert the first letter into uppercase.

Supported Versions

  • PHP 4
  • PHP 5
  • PHP 7
  • PHP 8

Example

echo ucwords("programming");
// Output: Programming

In the above example, a single word is passed into ucwords() function that converts the first letter into uppercase.

echo ucwords("programming is best");
// Output: Programming Is Best

In the above example, a phrase that contains three words is passed into the ucwords() function. As you can see in the output, the function converted the first letter of each word into uppercase.

Conclusion

This article demonstrates how can you use the PHP ucwords() function. It converts each letter of the string into uppercase and to do that you need to pass the string into the function as an argument.


Written by
I am a skilled full-stack developer with extensive experience in creating and deploying large and small-scale applications. My expertise spans front-end and back-end technologies, along with database management and server-side programming.

Share on:

Related Posts

Tags: PHP, PHP-Functions,