6 * @subpackage PluginsModifierCompiler
\r
10 * Smarty count_words modifier plugin
\r
12 * Type: modifier<br>
\r
13 * Name: count_words<br>
\r
14 * Purpose: count the number of words in a text
\r
16 * @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
\r
18 * @param array $params parameters
\r
19 * @return string with compiled code
\r
21 function smarty_modifiercompiler_count_words($params, $compiler)
\r
23 if (Smarty::$_MBSTRING) {
\r
24 // return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)';
\r
25 // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
\r
26 return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)';
\r
28 // no MBString fallback
\r
29 return 'str_word_count(' . $params[0] . ')';
\r