76 of 410 menu

The mb_strcut Function

The mb_strcut function is similar to substr, but works correctly with multibyte encodings. It takes a string as the first parameter, the starting position in characters (not bytes) as the second parameter, and the length of the substring to extract as the third parameter. The fourth optional parameter can specify the encoding.

Syntax

mb_strcut(string, start, length, [encoding]);

Example

Let's extract 3 characters from a UTF-8 string, starting from position 1:

<?php $str = 'Привет мир'; echo mb_strcut($str, 1, 3, 'UTF-8'); ?>

Code execution result:

'рив'

Example

Let's extract a substring to the end of the string from Cyrillic text:

<?php $str = 'Пример строки'; echo mb_strcut($str, 3, null, 'UTF-8'); ?>

Code execution result:

'мер строки'

See Also

  • the mb_substr function,
    which also works with multibyte strings
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