Erhan is typing…

WebDevelopment , PHP, Javascript, CakePHP, ExtJS

PHP: lcfirst

| Comments

I need to make the first character of the string lowercase. I know ucfirst exists and I supposed that there is a [lcfirst](http://us2.php.net/manual/en/function.lcfirst.php) one as well.

When I started to type lcfirst, Zend Studio didn’t suggest me a function with this name and it was interesting. PHP documentation says that it is available but it throws an exception. What the hack goes wrong?

Here is the answer: It was too late and too hard to keep my eyes open :)

lcfirst function is available in newly released version of PHP, 5.3. I am still using 5.2.9. Here is a code snippet:

1
2
3
4
5
if (!function_exists('lcfirst')) {
    function lcfirst($string) {
        return substr_replace($string, strtolower(substr($string, 0, 1)), 0, 1);
    }
}

It is unbelivable that I don’t ever need the function lcfirst before. :)

Comments