+3 votes
in Programming Languages by (56.7k 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

+1 vote
by (349k points)
selected by
 
Best answer

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?


...