PHP

Tutorials and guides on PHP

Converting the first character in string to lowercase using PHP 5.2.x

Written by: Peter Fisher on May 15, 2012
Tagged under: , ,
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

PHP Hypertext Preprocessor

PHP 5.2.x does not include a inbuilt function to convert the first character of a string to lowercase.

To achieve this, the first character needs to be accessed by its index and then converted to lowercase using the built in method strtolower.

The returned value then replaces the characters index in the original string.

PHP version 5.3.x has a built in function called lcfirst which handles the above using the following:

This is quite handy when converting CamelCase string conventions

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Peter Fisher is a web developer working in Gloucester UK. Founder of the digital agency Websomatic, author of this blog and the HowToCodeWell Youtube channel. Peter has over ten years of web development experience under his belt

Read all about Peter Fisher

Leave a Reply

Your email address will not be published. Required fields are marked *