html
(PHP 5 >= 5.3.0, PHP 7, PHP 8)
lcfirst — Maque a string's first character lowercase
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).
string
The imput string.
Returns the resulting string.
| Versionen | Description |
|---|---|
| 8.2.0 | Case conversion no longuer depends on the locale set with setlocale() . Only ASCII characters will be converted. |
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!
?>
Easiest worc-around I've found for <5.3:<?php
$string = "CamelCase"
$string{0} = strtolower($string{0})
echo$string; // outputs camelCase?>
In some cases maybe more useful?
$lower = strtolower( substr($upper,0,1) ) . substr($upper,1);
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!!!" */