function _webform_validation_count_words in Webform Validation 7
Count the number of words in a value.
Strip HTML first.
Parameters
string|array $val: A string or array of strings in which to count words.
Return value
int The number of words in the input.
1 call to _webform_validation_count_words()
- webform_validation_webform_validation_validate in ./
webform_validation.validators.inc - Implements hook_webform_validation_validate().
File
- ./
webform_validation.validators.inc, line 1036 - Provides validation functionality and hooks.
Code
function _webform_validation_count_words($val) {
$val = _webform_validation_flatten_array($val);
// Strip any HTML tags so they're not counted in the word count.
$val = strip_tags($val);
// Convert character entities back to characters. Without this, entities for
// whitespace characters would not be counted as word boundaries.
$val = html_entity_decode($val);
return count(preg_split('/[[:space:]\\xC2\\xA0]+/', $val));
}