lcfirst

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

lcfirst — Pone el primer carácter en minúscula

Descripción

function lcfirst(string $string): string

Devuelve una cadena cuyo primer carácter de string ha sido puesto en minúscula, si este carácter es un carácter ASCII en el rango que va de "A" (0x41) a "Z" (0x5a).

Parámetros

string

La cadena de entrada.

Valores devueltos

Devuelve la cadena resultante.

Historial de cambios

Versión Descripción
8.2.0 La conversión entre mayúsculas y minúsculas ya no depende de la configuración local definida con setlocale(). Solo se convertirán los caracteres ASCII.

Ejemplos

Ejemplo #1 Ejemplo con lcfirst()

<?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!
?>

Véase también

  • ucfirst() - Pone en mayúscula el primer carácter
  • strtolower() - Devuelve una string en minúsculas
  • strtoupper() - Devuelve una string en mayúsculas
  • ucwords() - Pone en mayúscula la primera letra de todas las palabras
+add a note

User Contributed Notes 3 notes

up
21
phpnet at katylavallee dot com
17 years ago
Easiest work-around I've found for <5.3:
<?php

$string = "CamelCase"
$string{0} = strtolower($string{0})
echo $string; // outputs camelCase

?>
up
7
alex aulbach
18 years ago
In some cases maybe more useful?

 $lower = strtolower( substr($upper,0,1) ) . substr($upper,1);
up
0
harmor
18 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'))
{
    /**
     * Make a string's first character lowercase
     *
     * @param string $str
     * @return string the resulting string.
     */
    function lcfirst( $str ) {
        $str[0] = strtolower($str[0]);
        return (string)$str;
    }
}

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