truncate_words()
function truncate_words(string $value, int $max_words): string
Description
Truncates a string to a specified maximum number of words. An ellipsis (...) is appended to indicate that the string has been shortened. This is useful for creating excerpts or previews of longer content.
Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
| $value | string | The input string to be truncated. | N/A |
| $max_words | int | The maximum number of words in the truncated string. | N/A |
Return Value
| Type | Description |
|---|---|
| string | The truncated string with an ellipsis if truncated. |