-
-
Save frzsombor/847d90bb11fbbcf52ee5270cb20266a2 to your computer and use it in GitHub Desktop.
mb_str_split function. multibyte version of str_split.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('mb_str_split')) { | |
/** | |
* Convert a multibyte string to an array | |
* | |
* @param string $string The input string. | |
* @param integer $split_length Maximum length of the chunk. | |
* @param string $encoding The encoding parameter is the character encoding. | |
* @return array | |
*/ | |
function mb_str_split($string, $split_length = 1, $encoding = null) | |
{ | |
if (is_null($encoding)) { | |
$encoding = mb_internal_encoding(); | |
} | |
if ($split_length < 1) { | |
return false; | |
} | |
$return_value = array(); | |
$string_length = mb_strlen($string, $encoding); | |
for ($i = 0; $i < $string_length; $i += $split_length) | |
{ | |
$return_value[] = mb_substr($string, $i, $split_length, $encoding); | |
} | |
return $return_value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment