public static function cutStringToWords($subject, $maxWordsCount, $trimChars = " \t\n\r\v") { self::$subjectChanged = false; $pattern = '/([^\\s\\n\\r]+[\\s\\n\\r]+){' . $maxWordsCount . '}/s'; if (self::$unicode) { $pattern .= 'u'; } if (preg_match($pattern, $subject, $match)) { $subject = rtrim($match[0], $trimChars); self::$subjectChanged = true; } return $subject; }