77 of 410 menu

The mb_strimwidth Function

The mb_strimwidth function trims a string to a given width, considering multi-byte characters. Its first parameter is the source string, the second is the starting position, and the third is the maximum string width in characters. An optional fourth parameter allows you to specify a string that will be added to the end of the trimmed string.

Syntax

mb_strimwidth(string, start, width, [trimmarker], [encoding]);

Example

Let's trim the string to 6 characters:

<?php $res = mb_strimwidth("Привет мир", 0, 6); echo $res; ?>

Code execution result:

'Привет'

Example

Let's trim the string adding an ellipsis at the end:

<?php $res = mb_strimwidth("Привет мир", 0, 8, "..."); echo $res; ?>

Code execution result:

'Привет...'

Example

Let's trim the string from the middle:

<?php $res = mb_strimwidth("Привет мир", 3, 5); echo $res; ?>

Code execution result:

'вет м'

See Also

  • the mb_substr function,
    which returns part of a string
  • the substr function,
    which returns a substring
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline