mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 14:28:27 +08:00
Added StringHelper::countWords()
that given a string returns number of words in it
This commit is contained in:
@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user