mb_strimwidth
Get string truncated by specified width
Function name: mb_strimwidth()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7
Usage: mb_strimwidth(string $str, int $start, int $width, string $trimmarker = "", string $encoding = null): string
Description: The mb_strimwidth() function truncates the string based on the specified width and adds an optional modifier at the end. This function is multibyte-safe and can correctly handle strings containing multibyte characters.
parameter:
Return value: Returns the truncated string.
Example:
$text = "这是一个示例文本,用于演示mb_strimwidth()函数的用法"; $trimmedText = mb_strimwidth($text, 0, 20, "..."); echo $trimmedText; // 输出:这是一个示例文本...
In the example above, we use the mb_strimwidth() function to truncate the text into a string of length 20, and if truncated, the ellipsis "..." is added at the end.