PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/include/utf8/ucfirst.php

https://bitbucket.org/yoorick/fluxbb.pe
PHP | 35 lines | 17 code | 2 blank | 16 comment | 1 complexity | d5a74f6c881f48091adcdaeb45fec542 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @version $Id: ucfirst.php,v 1.1 2006/02/25 13:50:17 harryf Exp $
  4. * @package utf8
  5. * @subpackage strings
  6. */
  7. /**
  8. * UTF-8 aware alternative to ucfirst
  9. * Make a string's first character uppercase
  10. * Note: requires utf8_strtoupper
  11. * @param string
  12. * @return string with first character as upper case (if applicable)
  13. * @see http://www.php.net/ucfirst
  14. * @see utf8_strtoupper
  15. * @package utf8
  16. * @subpackage strings
  17. */
  18. function utf8_ucfirst($str)
  19. {
  20. switch (utf8_strlen($str))
  21. {
  22. case 0:
  23. return '';
  24. break;
  25. case 1:
  26. return utf8_strtoupper($str);
  27. break;
  28. default:
  29. preg_match('/^(.{1})(.*)$/us', $str, $matches);
  30. return utf8_strtoupper($matches[1]).$matches[2];
  31. break;
  32. }
  33. }