ucwords.php 678 B

123456789101112131415161718192021222324
  1. <?php
  2. /**
  3. * UTF8::ucwords
  4. *
  5. * @package Kohana
  6. * @author Kohana Team
  7. * @copyright (c) Kohana Team
  8. * @copyright (c) 2005 Harry Fuecks
  9. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
  10. */
  11. function _ucwords($str)
  12. {
  13. if (UTF8::is_ascii($str))
  14. return ucwords($str);
  15. // [\x0c\x09\x0b\x0a\x0d\x20] matches form feeds, horizontal tabs, vertical tabs, linefeeds and carriage returns.
  16. // This corresponds to the definition of a 'word' defined at http://php.net/ucwords
  17. return preg_replace_callback(
  18. '/(?<=^|[\x0c\x09\x0b\x0a\x0d\x20])[^\x0c\x09\x0b\x0a\x0d\x20]/u',
  19. function($matches){
  20. return UTF8::strtoupper($matches[0]);
  21. },
  22. $str);
  23. }