5 * @subpackage plugins
\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
15 * @link http://smarty.php.net/manual/en/language.modifier.count.words.php
\r
16 * count_words (Smarty online manual)
\r
20 function smarty_modifier_count_words($string)
\r
22 // split text by ' ',\r,\n,\f,\t
\r
23 $split_array = preg_split('/\s+/',$string);
\r
24 // count matches that contain alphanumerics
\r
25 $word_count = preg_grep('/[a-zA-Z0-9\\x80-\\xff]/', $split_array);
\r
27 return count($word_count);
\r
30 /* vim: set expandtab: */
\r