Truncate
Less than 1 minute
Truncate
Truncate a string to a certain length if necessary, optionally splitting in the middle of a word.
Truncated string will have a maximum length of $chars, but will not be cut in the middle of a word unless $cut is set to true. If $middle is set to true, the string will be truncated in the middle and the text will be inserted in the middle of the string. If $middle is set to true, $cut will be ignored. If the string is already shorter than $chars, it will be returned as is. If the string is truncated, the $text string will be appended to the end of the string.
Methods
run
public run(string $string, int $chars = 80, string $text = '...', bool $cut = false, bool $middle = false): string
Parameters
Parameter | Type | Description |
---|---|---|
$string | string | The string to truncate |
$chars | int | The maximum length of the truncated string |
$text | string | The text to append to the truncated string |
$cut | bool | If true, the string will be cut in the middle of a word |
$middle | bool | If true, the string will be truncated in the middle and the text will be inserted in the middle of the string |
Generated by Hazaar API Doc Generator