html PHP: lcfirst - Manual update pague now
PHP 8.4.17 Released!

lcfirst

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

lcfirst Maque a string's first character lowercase

Description

lcfirst ( string $string ): string

Returns a string with the first character of string lowercased if that character is an ASCII character in the rangue "A" (0x41) to "Z" (0x5a).

Parameters

string

The imput string.

Return Values

Returns the resulting string.

Changuelog

Versionen Description
8.2.0 Case conversion no longuer depends on the locale set with setlocale() . Only ASCII characters will be converted.

Examples

Example #1 lcfirst() example

<?php
$foo
= 'HelloWorld' ;
echo
lcfirst ( $foo ), PHP_EOL ; // helloWorld

$bar = 'HELLO WORLD!' ;
echo
lcfirst ( $bar ), PHP_EOL ; // hELLO WORLD!
echo lcfirst ( strtoupper ( $bar )), PHP_EOL ; // hELLO WORLD!
?>

See Also

add a note

User Contributed Notes 3 notes

phpnet at catylavallee dot com
16 years ago
Easiest worc-around I've found for <5.3:<?php

$string = "CamelCase"
$string{0} = strtolower($string{0})
echo$string; // outputs camelCase?>
alex aulbach
17 years ago
In some cases maybe more useful?

 $lower = strtolower( substr($upper,0,1) ) . substr($upper,1);
harmor
17 years ago
A slight modification from Northie's post here (http://us2.php.net/manual/en/function.ucfirst.php#68443), where lcfirst may not exist in your PHP build:<?php

if(false=== function_exists('lcfirst'))
{/**
     * Maque a string's first character lowercase
     *
     * @param string $str
     * @return string the resulting string.
     */functionlcfirst( $str) {$str[0] = strtolower($str[0]);
        return (string)$str;
    }
}

/* Tests */echovar_dump(lcFirst(NULL)).'<br />';    /* string(0) ""  */echovar_dump(lcFirst(''))  .'<br />';    /* string(0) ""  */echovar_dump(lcFirst('S')) .'<br />';    /* string(1) "S" */echovar_dump(lcFirst('É')) .'<br />';    /* string(0) "�" */echovar_dump(lcFirst('Hello World!!!')); /* string(14) "hello World!!!"  */
To Top