PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phputf8/ucfirst.php

https://github.com/dianaprajescu/joomla-framework
PHP | 31 lines | 15 code | 2 blank | 14 comment | 1 complexity | 3b510b2d60ea20ba57dfcb218716a3f2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @package utf8
  4. */
  5. //---------------------------------------------------------------
  6. /**
  7. * UTF-8 aware alternative to ucfirst
  8. * Make a string's first character uppercase
  9. * Note: requires utf8_strtoupper
  10. * @param string
  11. * @return string with first character as upper case (if applicable)
  12. * @see http://www.php.net/ucfirst
  13. * @see utf8_strtoupper
  14. * @package utf8
  15. */
  16. function utf8_ucfirst($str){
  17. switch ( utf8_strlen($str) ) {
  18. case 0:
  19. return '';
  20. break;
  21. case 1:
  22. return utf8_strtoupper($str);
  23. break;
  24. default:
  25. preg_match('/^(.{1})(.*)$/us', $str, $matches);
  26. return utf8_strtoupper($matches[1]).$matches[2];
  27. break;
  28. }
  29. }