6 * @subpackage PluginsModifier
10 * Smarty capitalize modifier plugin
13 * Name: capitalize<br>
14 * Purpose: capitalize words in the string
17 * @author Monte Ohrt <monte at ohrt dot com>
21 function smarty_modifier_capitalize($string, $uc_digits = false)
23 // uppercase with php function ucwords
24 $upper_string = ucwords($string);
25 // check for any missed hyphenated words
26 $upper_string = preg_replace("!(^|[^\p{L}'])([\p{Ll}])!ue", "'\\1'.ucfirst('\\2')", $upper_string);
27 // check uc_digits case
29 if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!u", $string, $matches, PREG_OFFSET_CAPTURE)) {
30 foreach($matches[1] as $match)
31 $upper_string = substr_replace($upper_string, $match[0], $match[1], strlen($match[0]));