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