75 of 410 menu

The mb_str_split Function

The mb_str_split function splits a string in a multibyte encoding (for example, UTF-8) into an array of characters or parts of a specified length. The first parameter is the string to split, the second is the length of each part, and the third is the encoding.

Syntax

mb_str_split(string, [length], [encoding]);

Example

Let's split a string into individual characters:

<?php $res = mb_str_split('абвгд'); print_r($res); ?>

Code execution result:

['а', 'б', 'в', 'г', 'д']

Example

Let's split a string into parts of 2 characters each:

<?php $res = mb_str_split('12345', 2); print_r($res); ?>

Code execution result:

['12', '34', '5']

Example

Let's split a string with explicit specification of UTF-8 encoding:

<?php $res = mb_str_split('日本語', 1, 'UTF-8'); print_r($res); ?>

Code execution result:

['日', '本', '語']

See Also

  • the str_split function,
    which splits a string into an array
  • the explode function,
    which splits a string by a separator
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