Return to Snippet

Revision: 29435
at December 14, 2010 11:07 by Sverri


Updated Code
if ( ! function_exists('lcfirst'))
{
  function lcfirst($str)
  {
    if ( ! is_string($str))
    {
      throw new Exception("Subject must be of type string");
    }
    $str[0] = strtolower($str[0]);
 
    return $str;
  }
}

Revision: 29434
at July 29, 2010 13:05 by Sverri


Initial Code
if ( ! function_exists('lcfirst'))
{
  function lcfirst($str)
  {
    if ( ! is_string($str))
    {
      $bt = array_pop(debug_backtrace());
      
      return '<br /><b>Warning:</b>  lcfirst() expects parameter 1 to be string, '.gettype($str)
      . ' given in <b>'.$bt['file'].'</b> on line <b>'.$bt['line'].'</b></br />';
    }
    $str[0] = strtolower($str[0]);
    
    return $str;
  }
}

Initial URL

                                

Initial Description
Adds the function "lcfirst" if it does not exist (it was first added in PHP 5.3.0) while its counterpart, "ucfirst" was added in PHP 4.

Initial Title
Function \"lcfirst\" for PHP

Initial Tags

                                

Initial Language
PHP