Added StringHelper::countWords() that given a string returns number of words in it

This commit is contained in:
Alexander Makarov
2016-03-16 01:41:57 +03:00
parent b6d26a12e9
commit c17f887583
3 changed files with 22 additions and 0 deletions

View File

@ -270,4 +270,16 @@ class BaseStringHelper
}
return $result;
}
/**
* Counts words in a string
* @since 2.0.8
*
* @param string $string
* @return integer
*/
public static function countWords($string)
{
return count(preg_split('/\s+/u', $string, null, PREG_SPLIT_NO_EMPTY));
}
}