tags:

views:

143

answers:

2

As I know, strtolower makes the string all lowercase and ucfirst makes the string's first letter capitalised.

I am asking, is it possible to make every word within the string capitalised?

Example $string = "hello world" - How can I make this appear "Hello World"?

+11  A: 

You are looking for the ucwords function. Example straight from the PHP docs:

$foo = 'hello world!';
$foo = ucwords($foo);             // Hello World!

$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
Paolo Bergantino
+6  A: 

It's a good practice to make the entire string lowercase first just to ensure consistency.

$foo = ucwords(strtolower($string));
jerebear
If that's what you WANT to do.
Joe Philllips