+3 votes
in Programming Languages by (8.5k points)
I want to convert the first character of each word in a string to uppercase. What PHP function should I use?

e.g.

"hello brother, how are you?"

to

"Hello Brother, How Are You?"

1 Answer

0 votes
by (32.8k points)

You can use the ucwords() function. It converts the first character of each word in a string to uppercase. 

Here is an example:

<?php
$str = "hello brother, how are you?";
echo ucwords($str);
?>

The above code will return the following output:

Hello Brother, How Are You?

...