truncate.php
Table of Contents
Functions
- truncate() : string
- Truncates a string to a maximum number of grapheme clusters, appending an ellipsis.
Functions
truncate()
Truncates a string to a maximum number of grapheme clusters, appending an ellipsis.
truncate(string $source, int $length[, string $ellipsis = '…' ]) : string
The length is counted in grapheme clusters, so multibyte characters and combined
emojis are never split. When the source is longer than $length, it is cut to the
first $length graphemes and $ellipsis is appended (the ellipsis is not counted
in $length). Shorter or equal strings are returned unchanged.
Parameters
- $source : string
-
The input string.
- $length : int
-
The maximum number of grapheme clusters to keep.
- $ellipsis : string = '…'
-
The string appended when truncation occurs. Default
….
Tags
Return values
string —The truncated string, or the original when no truncation is needed.