Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.0 KiB

  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Smarty capitalize modifier plugin
  9. *
  10. * Type: modifier<br>
  11. * Name: capitalize<br>
  12. * Purpose: capitalize words in the string
  13. * @link http://smarty.php.net/manual/en/language.modifiers.php#LANGUAGE.MODIFIER.CAPITALIZE
  14. * capitalize (Smarty online manual)
  15. * @author Monte Ohrt <monte at ohrt dot com>
  16. * @param string
  17. * @return string
  18. */
  19. function smarty_modifier_capitalize($string, $uc_digits = false)
  20. {
  21. smarty_modifier_capitalize_ucfirst(null, $uc_digits);
  22. return preg_replace_callback('!\'?\b\w(\w|\')*\b!', 'smarty_modifier_capitalize_ucfirst', $string);
  23. }
  24. function smarty_modifier_capitalize_ucfirst($string, $uc_digits = null)
  25. {
  26. static $_uc_digits = false;
  27. if(isset($uc_digits)) {
  28. $_uc_digits = $uc_digits;
  29. return;
  30. }
  31. if(substr($string[0],0,1) != "'" && !preg_match("!\d!",$string[0]) || $_uc_digits)
  32. return ucfirst($string[0]);
  33. else
  34. return $string[0];
  35. }
  36. ?>