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
views:
49answers:
4
+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
2010-04-09 09:51:10
Nice, didn't know this one! +1.
Pekka
2010-04-09 09:53:10
Thanks for the help, this worked for me.
streetparade
2010-04-09 09:53:11
+2
A:
Use ucfirst()
See the list of string functions, it will answer most of your string related questions.
Pekka
2010-04-09 09:51:21
+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
2010-04-09 09:51:34
+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
2010-04-09 09:54:33