1 <?php
2 /**
3 * Smarty plugin
4 *
5 * @package Smarty
6 * @subpackage PluginsModifier
7 */
9 /**
10 * Smarty capitalize modifier plugin
11 *
12 * Type: modifier<br>
13 * Name: capitalize<br>
14 * Purpose: capitalize words in the string
15 *
16 * @link
17 * @author Monte Ohrt <monte at ohrt dot com>
18 * @param string $
19 * @return string
20 */
21 function smarty_modifier_capitalize($string, $uc_digits = false)
22 {
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
28 if (!$uc_digits) {
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]));
32 }
33 }
34 return $upper_string;
35 }
37 ?>