Can this work for splitting a multi-byte string every ten characters?
$string = 'Star Wars Episode Seven Sucked';
mb_split('.', $string, 10);
The PHP manual says that str_split()
works on bytes, not characters in multi-byte strings. That means mb_split()
would seem to be a natural "overloaded" substitution, but the two functions (str_split()
and mb_split()
) have different function signatures and are not "overload buddies," so to speak. Then, I had a thought, what about this?
mb_internal_encoding("UTF-8");
$string = 'Star Wars Episode Seven Sucked';
$tokens = [];
for($i = 0, $length = mb_strlen($string); $i < $length; $i += 10)
{
$tokens[] = mb_substr($string, $i, 10, 'UTF-8');
}
print_r($tokens);