Edit report at https://bugs.php.net/bug.php?id=62051&edit=1
ID: 62051
Comment by: jan dot bouvrie at gmail dot com
Reported by: info at javabar dot de
Summary: missing function: mb_str_split()
Status: Wont fix
Type: Feature/Change Request
Package: mbstring related
Operating System: all
PHP Version: Irrelevant
Assigned To: moriyoshi
Block user comment: N
Private report: N
New Comment:
@moriyoshi
array str_split (string $string[, int $split_length = 1 ])
Converts a string to an array.
array mb_split (string $pattern, string $string [, int $limit = -1 ])
Split a multibyte string using regular expression pattern and returns the
result as an array.
Performance-wise, I wouldn't say mb_split (using a regular expression) is the
same as str_split? Also, I'm curious how to call mb_split with a proper regexp
so that it simulates str_split?
Example:
<?php
function mb_str_split($str, $length = 1)
{
if ($length < 1) return FALSE;
$result = array();
for ($i = 0; $i < mb_strlen($str); $i += $length) {
$result[] = mb_substr($str, $i, $length);
}
return $result;
}
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
$test='ÓÓç«è½¦ç¥¨abc';
print_r(preg_split('/(?<!^)(?!$)/u', $test));
print_r(mb_str_split($test));
print_r(mb_split('/./',$test));
?>
outputs:
Array
(
[0] => Ó
[1] => Ó
[2] => ç«
[3] => 车
[4] => 票
[5] => a
[6] => b
[7] => c
)
Array
(
[0] => Ó
[1] => Ó
[2] => ç«
[3] => 车
[4] => 票
[5] => a
[6] => b
[7] => c
)
Array
(
[0] => ÓÓç«è½¦ç¥¨abc
)
Previous Comments:
------------------------------------------------------------------------
[2012-06-02 06:10:48] [email protected]
I have the impression that mb_split() pretty much does the expected work,
unless
we really want a counterpart of every byte-wise string function in mbstring...
------------------------------------------------------------------------
[2012-05-19 06:48:19] [email protected]
moriyoshi sama, what do you think about this FR? thanks
------------------------------------------------------------------------
[2012-05-17 06:26:25] info at javabar dot de
Description:
------------
The multibyte version of str_split(), which splits a string into an array of
chunks, does not seem to be implementated yet.
The name should be: mb_str_split()
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62051&edit=1