PHP 8.5.0 Alpha 1 available for testing

lcfirst

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

lcfirstPone el primer carácter en minúscula

Descripción

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 Case conversion no longer depends on the locale set with setlocale(). Only ASCII characters will be converted.

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

Ver 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
16 years ago
Easiest work-around I've found for <5.3:
<?php

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

?>
up
6
alex aulbach
16 years ago
In some cases maybe more useful?

$lower = strtolower( substr($upper,0,1) ) . substr($upper,1);
up
0
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'))
{
/**
* 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!!!" */
To Top