mb_strimwidth
Truncates a string to a given width and appends a marker.
Syntax
mb_strimwidth(string $string, int $start, int $width, string $trim_marker = ""): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The source string. |
| $start | int | The position to start at. |
| $width | int | The maximum width of the result including the marker. |
| $trim_marker | string | Optional. What to append to a truncated string. |
Return value
stringThe truncated string.
Examples
A post teaser with an ellipsis:
<?php
echo mb_strimwidth('A very long title of an article', 0, 15, '...');Output:
A very long ...A short string is left alone:
<?php
echo mb_strimwidth('Short', 0, 15, '...');Output:
ShortNotes
The marker counts towards the width. A string that already fits is returned without the marker.
See also
In the tutorial
- Strings — Working with strings in PHP — quotes, concatenation, length, searching, replacing and multibyte functions.