ucwords.php 704 B

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