Here is an example that works with multibyte ( UTF-8 ) strings.
$str = 'äbcd';
// PHP 5.4.8 allows null as the third argument of mb_strpos() function
do {
$arr[] = mb_substr( $str, 0, 1, 'utf-8' );
} while ( $str = mb_substr( $str, 1, mb_strlen( $str ), 'utf-8' ) );
It can be also done with preg_split()
( preg_split( '//u', $str, null, PREG_SPLIT_NO_EMPTY )
), but unlike the above example, that runs almost as fast regardless of the size of the string, preg_split()
is fast with small strings, but a lot slower with large ones.