Files
smarty/libs/plugins/modifier.count_words.php

33 lines
703 B
PHP
Raw Normal View History

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