src/Common/TextUtils.php
public static function countWords(string $text): int
    {
        // split text by ' ',\r,\n,\f,\t
        $split_array = preg_split('/\s+/', $text);
        // count matches that contain alphanumerics
        $word_count = preg_grep('/[a-zA-Z0-9\\x80-\\xff]/', $split_array);

        return count($word_count);
    }
public static function countWords(string $text): int
    {
        // split text by ' ',\r,\n,\f,\t
        $split_array = preg_split('/\s+/', $text);
        // count matches that contain alphanumerics
        $word_count = preg_grep('/[a-zA-Z0-9\\x80-\\xff]/', $split_array);

        return count($word_count);
    }
public static function countWords ( string $ text ) : int { // split text by ' ',\r,\n,\f,\t $ split_array = preg_split ( '/\s+/' , $ text ) ; // count matches that contain alphanumerics $ word_count = preg_grep ( '/[a-zA-Z0-9\\x80-\\xff]/' , $ split_array ) ; return count ( $ word_count ) ; }
Count the number of words in a text
@param string $text
@return int
Count the number of words in a text