php truncateTextByWords(string $string, int $maxWords = 10): string

return preg_replace(‘/((\w+\W*){‘ . ($maxWords – 1) . ‘}(\w+))(.*)/’, ‘${1}’, $string)