tags:

views:

49

answers:

4

I need to know how i can make a string like "hello" to "Hello" using PHP? I just need the first character to be Upper

+7  A: 

use the function ucwords(); This will do every word in the string, using ucfirst() will just do the first word.

echo ucwords('hello my name is jim');

// Hello My Name Is Jim

echo ucfirst('hello my name is jim');

// Hello my name is jim
Lizard
Nice, didn't know this one! +1.
Pekka
Thanks for the help, this worked for me.
streetparade
+2  A: 

Use ucfirst()

See the list of string functions, it will answer most of your string related questions.

Pekka
+3  A: 

You need the ucfirst function.

Returns a string with the first character of str capitalized, if that character is alphabetic.

It will not make the other characters lowercase. To make sure only the first letter is upper case and rest all are lowercase you can do:

ucfirst(strtolower($str))
codaddict
+1  A: 

For: first char of string

Use: ucfirst("first char of string"); //output First char of string

For: all first char of word in string

Use: ucwords("all first char of word in string") // output All First Char Of Word In String

nik