[ Index ]

krapohl.info

title

Body

[close]

/pnincludes/Smarty/plugins/ -> modifier.count_words.php (source)

   1  <?php
   2  
   3  /*
   4   * Smarty plugin
   5   * -------------------------------------------------------------
   6   * Type:     modifier
   7   * Name:     count_words
   8   * Purpose:  count the number of words in a text
   9   * -------------------------------------------------------------
  10   */
  11  function smarty_modifier_count_words($string)
  12  {
  13      // split text by ' ',\r,\n,\f,\t
  14      $split_array = preg_split('/\s+/',$string);
  15      // count matches that contain alphanumerics
  16      $word_count = preg_grep('/[a-zA-Z0-9]/', $split_array);
  17  
  18      return count($word_count);
  19  }
  20  
  21  /* vim: set expandtab: */
  22  
  23  ?>


Generated: Wed Feb 16 22:40:07 2005 Cross-referenced by PHPXref 0.6