`ucwords()`: Capitalize the First Letter of Each Word in a String


**`ucwords()`: Capitalize the First Letter of Each Word in a String**

The `ucwords()` function is a built-in PHP function that converts the first character of each word in a string to uppercase. This function is often used to capitalize the first letter of each word in a title or heading.

**Syntax**

“`
string ucwords ( string $string )
“`

**Parameters**

* `$string`: The string to capitalize.

**Return Value**

The `ucwords()` function returns a string with the first character of each word capitalized.

**Example**

The following example shows how to use the `ucwords()` function to capitalize the first letter of each word in a string:

“`
$string = “hello world”;
$capitalizedString = ucwords($string);

echo $capitalizedString; // Output: Hello World
“`

**Additional Notes**

* The `ucwords()` function does not capitalize the first letter of the first word in a string if the first character of the string is a number.
* The `ucwords()` function does not capitalize the first letter of a word that is preceded by a hyphen (-).
* The `ucwords()` function does not capitalize the first letter of a word that is followed by a period (.), comma (,), or semicolon (;).

**Use Cases**

The `ucwords()` function can be used in a variety of applications, including:

* Capitalizing the first letter of each word in a title or heading
* Capitalizing the first letter of each word in a product name
* Capitalizing the first letter of each word in a person’s name
* Capitalizing the first letter of each word in a company name

**Conclusion**

The `ucwords()` function is a versatile function that can be used to capitalize the first letter of each word in a string. This function is often used to capitalize the first letter of each word in a title or heading.