Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty plugin
Chris PeBenito 696b41
 * @package Smarty
Chris PeBenito 696b41
 * @subpackage plugins
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty count_words modifier plugin
Chris PeBenito 696b41
 *
Chris PeBenito 696b41
 * Type:     modifier
Chris PeBenito 696b41
 * Name:     count_words
Chris PeBenito 696b41
 * Purpose:  count the number of words in a text
Chris PeBenito 696b41
 * @link http://smarty.php.net/manual/en/language.modifier.count.words.php
Chris PeBenito 696b41
 *          count_words (Smarty online manual)
Chris PeBenito 696b41
 * @param string
Chris PeBenito 696b41
 * @return integer
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
function smarty_modifier_count_words($string)
Chris PeBenito 696b41
{
Chris PeBenito 696b41
    // split text by ' ',\r,\n,\f,\t
Chris PeBenito 696b41
    $split_array = preg_split('/\s+/',$string);
Chris PeBenito 696b41
    // count matches that contain alphanumerics
Chris PeBenito 696b41
    $word_count = preg_grep('/[a-zA-Z0-9\\x80-\\xff]/', $split_array);
Chris PeBenito 696b41
Chris PeBenito 696b41
    return count($word_count);
Chris PeBenito 696b41
}
Chris PeBenito 696b41
Chris PeBenito 696b41
/* vim: set expandtab: */
Chris PeBenito 696b41
Chris PeBenito 696b41
?>