Page 1 of 1

Capitalize only the first Letter of a string

Posted: Tue Oct 02, 2012 8:53 pm
by Live24x7
I want to Capitalize onlt the first Letter of a string.
I tried ucfirst($string) but it also capitalizes every word that comes after 'and' & ','.

With ucfirst, what i get is this:
Fifteen thousand, Nine hundred and Fourty-two

where as i want :
Fifteen thousand, nine hundred and fourty-two

Any suggestions ?
Thanks a lot !
:)

Re: Capitalize only the first Letter of a string

Posted: Tue Oct 02, 2012 9:03 pm
by Benjamin

Code: Select all

echo ucfirst(strtolower("Fifteen thousand, Nine hundred and Fourty-two"));
;)

Re: Capitalize only the first Letter of a string

Posted: Tue Oct 02, 2012 9:40 pm
by Live24x7
that works perfect thanks a lot :)

but i failed to understand how this worked ... it first lowered the case of entire string and then used ucfirst.
My original string is always all lowercase and i don't understand what affect did strtolower have on the string.

Re: Capitalize only the first Letter of a string

Posted: Tue Oct 02, 2012 10:26 pm
by Benjamin
I think you are missing something, ucfirst should only change the first character. Maybe you are using a different variable or source?