public static function countWords($string)
    {
        $result = preg_split('/\s+/u', $string, null, PREG_SPLIT_NO_EMPTY);
        return !empty($result) ? count($result) : 0;
    }
public static function countWords($string)
    {
        $result = preg_split('/\s+/u', $string, null, PREG_SPLIT_NO_EMPTY);
        return !empty($result) ? count($result) : 0;
    }
public static function countWords ( $ string ) { $ result = preg_split ( '/\s+/u' , $ string , null , PREG_SPLIT_NO_EMPTY ) ; return ! empty ( $ result ) ? count ( $ result ) : 0 ; }
Counts words in a string.

@param string $string
@return int
Counts words in a string .