I would like to split a string which contains emojis. I don't understand why my function generates an empty character.
Code :
function str_split_unicode($str, $l = 0) {
if ($l > 0) {
$ret = array();
$len = mb_strlen($str, "UTF-8");
for ($i = 0; $i < $len; $i += $l) {
$ret[] = mb_substr($str, $i, $l, "UTF-8");
}
return $ret;
}
return preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
}
$emoji_value = "⬜️";
$emoji_split = str_split_unicode($emoji_value,1);
print_r($emoji_split);
Result :
Array
(
[0] =>
[1] => ⬜
[2] => ️
[3] =>
)
Hope it`s clear. Any help is greatly appreciated!