php
Uppercase first character of each word of a String in PHP
September 18, 2022
If you need to uppercase the first character of each word in a string in PHP, you can use the ucwords() function. This function takes a string as an argument and returns a new string with the first character of each word in the original string capitalized.
<?php
$str = "hello world";
$res = ucwords($str);
echo $res;
?>
Output
Hello World
To convert the first letter of each word of a String to uppercase:
- Define a String that contains some words.
- Pass the string to the ucwords() function that will return the string with each word having the first character uppercase.
- print the string.
Syntax
ucwords($str)
Was this helpful?
Similar Posts