30秒学会 PHP 片段 · 2018年3月17日

30秒学会 PHP 片段 – decapitalize

Decapitalizes the first letter of a string.

Decapitalizes the first letter of the string and then adds it with rest of the string.
Omit the $upperRest parameter to keep the rest of the string intact, or set it to true to convert to uppercase.

代码实现

function decapitalize($string, $upperRest = false)
{
  return lcfirst($upperRest ? strtoupper($string) : $string);
}

使用样例

decapitalize('FooBar'); // 'fooBar'