how to lowercase the first letter in a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

how to lowercase the first letter in a string

Post by jasongr »

Hello

Assume I have a string like so:
$test = 'Hello My Name is John";

I would like to lowercase the first letter in the string so the stringw will become

"hello My Name is John"

I saw function ucfirst(), but there is no lcfirst()

you can assume that the first letter is latin

regards
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You could make use of strtolower(substr($test, 1, 1)) or somethnig similiar, combined with other string functions.

Fins first letter, strtolower it and put it back in.
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

Here is a simple solution I found:

Code: Select all

$string{0} = strtolower($string{0});
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

jasongr wrote:Here is a simple solution I found:

Code: Select all

$string{0} = strtolower($string{0});
That would be easier, yes. :wink:
Post Reply